fix(config_parser): UB in logger
Because we passed a temporary as the logger, it gets destroyed after the config_parser constructor returns and when the logger is called in config_parser it operates on a dangling reference. Ref: https://stackoverflow.com/q/35770357/5363071
This commit is contained in:
parent
04344aa0e7
commit
eaa50691fc
@ -88,6 +88,11 @@ struct line_t {
|
||||
class config_parser {
|
||||
public:
|
||||
config_parser(const logger& logger, string&& file, string&& bar);
|
||||
/**
|
||||
* This prevents passing a temporary logger to the constructor because that would be UB, as the temporary would be
|
||||
* destroyed once the constructor returns.
|
||||
*/
|
||||
config_parser(logger&& logger, string&& file, string&& bar) = delete;
|
||||
|
||||
/**
|
||||
* \brief Performs the parsing of the main config file m_file
|
||||
|
@ -33,8 +33,8 @@ class TestableConfigParser : public config_parser {
|
||||
*/
|
||||
class ConfigParser : public ::testing::Test {
|
||||
protected:
|
||||
unique_ptr<TestableConfigParser> parser =
|
||||
make_unique<TestableConfigParser>(logger(loglevel::NONE), "/dev/zero", "TEST");
|
||||
const logger l = logger(loglevel::NONE);
|
||||
unique_ptr<TestableConfigParser> parser = make_unique<TestableConfigParser>(l, "/dev/zero", "TEST");
|
||||
};
|
||||
|
||||
// ParseLineTest {{{
|
||||
|
Loading…
Reference in New Issue
Block a user