Make scope_logger hold a copy of the string.
The previous version held a pointer to the string used to initialize the object. This failed when the string used to create the object is a temporary object. It works for the constructor but in the destructor the pointer might be invalid.
This commit is contained in:
parent
d2a6e86be1
commit
3e2b618839
2 changed files with 6 additions and 6 deletions
|
@ -126,7 +126,7 @@ std::ostream &logger::operator()(log_domain const &domain, bool show_names, bool
|
|||
}
|
||||
}
|
||||
|
||||
void scope_logger::do_log_entry(log_domain const &domain, const char* str)
|
||||
void scope_logger::do_log_entry(log_domain const &domain, const std::string& str)
|
||||
{
|
||||
output_ = &debug(domain, false, true);
|
||||
str_ = str;
|
||||
|
|
10
src/log.hpp
10
src/log.hpp
|
@ -75,21 +75,21 @@ class scope_logger
|
|||
{
|
||||
int ticks_;
|
||||
std::ostream *output_;
|
||||
const char* str_;
|
||||
std::string str_;
|
||||
public:
|
||||
scope_logger(log_domain const &domain, const char* str) :
|
||||
ticks_(0),
|
||||
output_(0),
|
||||
str_(0)
|
||||
str_()
|
||||
{
|
||||
if (!debug.dont_log(domain)) do_log_entry(domain, str);
|
||||
}
|
||||
scope_logger(log_domain const &domain, const std::string& str) :
|
||||
ticks_(0),
|
||||
output_(0),
|
||||
str_(0)
|
||||
str_()
|
||||
{
|
||||
if (!debug.dont_log(domain)) do_log_entry(domain, str.c_str());
|
||||
if (!debug.dont_log(domain)) do_log_entry(domain, str);
|
||||
}
|
||||
~scope_logger()
|
||||
{
|
||||
|
@ -97,7 +97,7 @@ public:
|
|||
}
|
||||
void do_indent() const;
|
||||
private:
|
||||
void do_log_entry(log_domain const &domain, const char* str);
|
||||
void do_log_entry(log_domain const &domain, const std::string& str);
|
||||
void do_log_exit();
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue