Re: [PATCH] don't store temporary value returned from c_str()

Subject: Re: [PATCH] don't store temporary value returned from c_str()

Date: Mon, 29 Apr 2013 18:23:01 -0300

To: Vladimir Marek, Jani Nikula

Cc: notmuch@notmuchmail.org

From: David Bremner


Vladimir Marek <Vladimir.Marek@Oracle.COM> writes:

>> It's okay to use the result of .c_str() as long as the string object
>> stays in scope, and none of the non-const member functions are
>> called. Here, I think the problem is that TermIterator's overloaded
>> operator*() returns a string object within the if block's scope, and it
>> goes immediately out of scope. You could check this by adding
>
> Right, I overlooked that TermIterator creates temporary string (if I
> understand you correctly).
>
>> fine too.
>
> I would prefer my change as it avoids creating another std::string. At
> least I think.

Would you mind updating your commit message to reflect the best guesses
from this discussion? 

d

Thread: