[PATCH 01/24] lib/message.cc: stale pointer bug
Tomi Ollila
tomi.ollila at iki.fi
Thu May 2 11:03:20 PDT 2013
On Thu, May 02 2013, Vladimir Marek <Vladimir.Marek at Oracle.COM> wrote:
>> > int prefix_len = strlen (prefix);
>> > - const char *term = NULL;
>> > + std::string term;
>> > char *value;
>> >
>> > i.skip_to (prefix);
>> >
>> > - if (i != end)
>> > - term = (*i).c_str ();
>> > + if (i == end)
>> > + return NULL;
>> >
>> > - if (!term || strncmp (term, prefix, prefix_len))
>> > + term = *i;
>>
>> ... hmm, a raii(?) solution above would be std::string term = *i;
>
> I'm not sure what's raii (I'm not very good at c++ ...), but I guess you
> mean to use 'std::string term = *i;' to avoid copy constructor. That
> surely is a good idea. Let me rework the patch!
I am not that smart (i.e. avoid copy constructor it might be, I don't
know...) I am lousy in c++. I attempter to mean
http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization
in a sense that when variable is introduced it is also initialized
to useful value (so that no-one accidentally add code between introduction
and initialization).
Anyway, if you rework the patch then we can vote which version to
apply (yeah, sure >;)
> --
> Vlad
Tomi
More information about the notmuch
mailing list