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

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

Date: Sat, 27 Apr 2013 12:33:16 +0300

To: Vladimir.Marek@oracle.com, notmuch@notmuchmail.org

Cc: Vladimir Marek

From: Tomi Ollila


On Sat, Apr 20 2013, Vladimir.Marek@oracle.com wrote:

> From: Vladimir Marek <vlmarek@volny.cz>
>
> This is causing problems when compiled by Oracle Studio. Memory pointed
> by (const char*)term was already changed once talloc_strdup was called.

If that changes, I'd like to understand why (and stated in the commit
message). If that is clear to everyone else I will withdraw the question --
I am not too familiar with these iterators magic... :D

Tomi

>
> Signed-off-by: Vladimir Marek <vlmarek@volny.cz>
> ---
>  lib/message.cc |    9 ++++-----
>  1 files changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/lib/message.cc b/lib/message.cc
> index 8720c1b..8d329d1 100644
> --- a/lib/message.cc
> +++ b/lib/message.cc
> @@ -266,18 +266,17 @@ _notmuch_message_get_term (notmuch_message_t *message,
>  			   const char *prefix)
>  {
>      int prefix_len = strlen (prefix);
> -    const char *term = NULL;
>      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))
> +    if (strncmp ((*i).c_str(), prefix, prefix_len))
>  	return NULL;
>  
> -    value = talloc_strdup (message, term + prefix_len);
> +    value = talloc_strdup (message, (*i).c_str() + prefix_len);
>  
>  #if DEBUG_DATABASE_SANITY
>      i++;
> -- 
> 1.7.3.2
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

Thread: