Author: mordante
Date: Sun Sep 28 23:11:13 2008
New Revision: 29749

URL: http://svn.gna.org/viewcvs/wesnoth?rev=29749&view=rev
Log:
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.

Modified:
    trunk/src/log.cpp
    trunk/src/log.hpp

Modified: trunk/src/log.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/log.cpp?rev=29749&r1=29748&r2=29749&view=diff
==============================================================================
--- trunk/src/log.cpp (original)
+++ trunk/src/log.cpp Sun Sep 28 23:11:13 2008
@@ -126,7 +126,7 @@
        }
 }
 
-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;

Modified: trunk/src/log.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/log.hpp?rev=29749&r1=29748&r2=29749&view=diff
==============================================================================
--- trunk/src/log.hpp (original)
+++ trunk/src/log.hpp Sun Sep 28 23:11:13 2008
@@ -75,21 +75,21 @@
 {
        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 @@
        }
        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();
 };
 


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to