[PATCH 01/24] lib/message.cc: stale pointer bug
Tomi Ollila
tomi.ollila at iki.fi
Thu May 2 03:01:47 PDT 2013
On Thu, May 02 2013, Vladimir.Marek at oracle.com wrote:
> From: Vladimir Marek <vlmarek at volny.cz>
>
> Xapian::TermIterator::operator* returns std::string which is destroyed
> as soon as (*i).c_str() finishes. The remembered pointer 'term' then
> references invalid memory.
Looks to me like a good solution...
Tomi
>
> Signed-off-by: Vladimir Marek <vlmarek at volny.cz>
> ---
> lib/message.cc | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/lib/message.cc b/lib/message.cc
> index 8720c1b..a890550 100644
> --- a/lib/message.cc
> +++ b/lib/message.cc
> @@ -266,18 +266,19 @@ _notmuch_message_get_term (notmuch_message_t *message,
> const char *prefix)
> {
> 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;
> + if (strncmp (term.c_str(), prefix, prefix_len))
> return NULL;
>
> - value = talloc_strdup (message, term + prefix_len);
> + value = talloc_strdup (message, term.c_str() + prefix_len);
>
> #if DEBUG_DATABASE_SANITY
> i++;
> --
> 1.7.9.2
>
> _______________________________________________
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
More information about the notmuch
mailing list