[Aptitude-devel] Stepping down as maintainer/developer
jorrit at jorrit.de
Wed Mar 14 20:49:55 UTC 2012
Am Fri, 2. Mar 2012, 23:27:33 +0800 schrieb Daniel Hartwig:
> On 2 March 2012 22:26, Jens Seidel <jensseidel at users.sf.net> wrote:
> > + return theme_config->FindVector((themeroot+Name).c_str());
> That is certainly an issue to be aware of. In this case it is safe to
> call FindVector like this as the temporary string will remain allocated
> until the function returns.
> I have been using such temporaries extensively in recent changes. I
> did have the same concern as yourself when I started so I checked this
> out with a small test program first and found some confirmation
> online (though did not manage to locate anything in C++ reference).
>  http://stackoverflow.com/questions/7581680/pass-c-str-return-value-of-temporary-object-to-printf
Such tests are are useful but should be taken with a grain of salt, since they
can succeed when you actually have undefined behaviour (e.g. use after free).
According to the standard (§12.2 paragraph 3) you should be OK provided
FindVector() doesn't store a reference or pointer into its argument string
somewhere (e.g. in its return value). Guessing from the name of the function
it just returns are reference into the container *theme_config, so there
shouldn't be a problem.
The basic rule is that the lifetime of a temporary extends until the execution
of the full-expression ends. In this case this means until the end of
"theme_config->FindVector((themeroot+Name).c_str())". Of course, every basic
rule has exceptions (see §12.2 paragraphs 4 and 5), but I dont think they
Latest freely accessible draft...
Jorrit (Jö) Fahlke, Interdisciplinary Center for Scientific Computing,
Heidelberg University, Im Neuenheimer Feld 368, D-69120 Heidelberg
Tel: +49 6221 54 8890 Fax: +49 6221 54 8884
If you receive something that says "Send this to everyone you know,"
pretend you don't know me.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 828 bytes
Desc: Digital signature
More information about the Aptitude-devel