Author: mordante
Date: Sat Apr 18 00:46:20 2009
New Revision: 34993

URL: http://svn.gna.org/viewcvs/wesnoth?rev=34993&view=rev
Log:
Add some comment about an unsafe situation.

Modified:
    trunk/src/variable.hpp

Modified: trunk/src/variable.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/variable.hpp?rev=34993&r1=34992&r2=34993&view=diff
==============================================================================
--- trunk/src/variable.hpp (original)
+++ trunk/src/variable.hpp Sat Apr 18 00:46:20 2009
@@ -60,10 +60,18 @@
        vconfig child(const std::string& key) const;
        bool has_child(const std::string& key) const;
 
-       /* Note: vconfig::operator[] returns const, and this should not be 
changed
-          because vconfig is often used as a drop-in replacement for config, 
and
-          this const will properly warn you if you try to assign 
vcfg["key"]=val;
-       */
+       /**
+        * Note: vconfig::operator[] returns const, and this should not be 
changed
+        * because vconfig is often used as a drop-in replacement for config, 
and
+        * this const will properly warn you if you try to assign 
vcfg["key"]=val;
+        *
+        * Note: The following construction is unsave:
+        * const std::string& temp = vcfg["foo"];
+        * This bind temp to a member of a temporary t_string. The lifetime of 
the
+        * temporary is not extended by this reference binding and the 
temporary's
+        * lifetime ends which causes UB. Instead use:
+        * const std::string temp = vcfg["foo"];
+        */
        const t_string operator[](const std::string& key) const { return 
expand(key); }
        const t_string expand(const std::string&) const; /** < Synonym for 
operator[] */
        bool has_attribute(const std::string& key) const { return 
cfg_->has_attribute(key); }


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

Reply via email to