unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jani Nikula <jani@nikula.org>
To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
Subject: Re: [PATCH] lib: another iterator-temporary/stale-pointer bug
Date: Thu, 01 Jan 2015 16:49:31 +0200	[thread overview]
Message-ID: <87wq56wo78.fsf@nikula.org> (raw)
In-Reply-To: <1419763508-11902-1-git-send-email-david@tethera.net>

On Sun, 28 Dec 2014, David Bremner <david@tethera.net> wrote:
> Tamas Szakaly points out [1] that the bug fixed in 51b073c still
> exists in at least one place. This change follows the suggestion of
> [2] and creates a block scope temporary std::string to avoid the rules
> of iterators temporaries.
>
> [1]: id:20141226113755.GA64154@pamparam
> [2]: id:20141226230655.GA41992@pamparam
> ---
>
> I decided to take a more minimalist approach than [2]. In particular
> using "direntry" for two different things seemed slightly trickier
> than necessary, for no obvious performance gain (calling .c_str()
> should be cheap).
>
> lib/message.cc | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/lib/message.cc b/lib/message.cc
> index a7a13cc..bacb4d4 100644
> --- a/lib/message.cc
> +++ b/lib/message.cc
> @@ -641,15 +641,16 @@ _notmuch_message_add_directory_terms (void *ctx, notmuch_message_t *message)
>  	unsigned int directory_id;
>  	const char *direntry, *directory;
>  	char *colon;
> +	const std::string term = *i;

You could use a reference here like in [2]. Either way, LGTM.

Jani.

>  
>  	/* Terminate loop at first term without desired prefix. */
> -	if (strncmp ((*i).c_str (), direntry_prefix, direntry_prefix_len))
> +	if (strncmp (term.c_str (), direntry_prefix, direntry_prefix_len))
>  	    break;
>  
>  	/* Indicate that there are filenames remaining. */
>  	status = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
>  
> -	direntry = (*i).c_str ();
> +	direntry = term.c_str ();
>  	direntry += direntry_prefix_len;
>  
>  	directory_id = strtol (direntry, &colon, 10);
> -- 
> 2.1.3
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

  reply	other threads:[~2015-01-01 14:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-26 11:37 BUG: Using pointer that points to a destructed string's content Tamas Szakaly
2014-12-26 22:03 ` David Bremner
2014-12-26 23:06   ` Tamas Szakaly
2014-12-28 10:45     ` [PATCH] lib: another iterator-temporary/stale-pointer bug David Bremner
2015-01-01 14:49       ` Jani Nikula [this message]
2015-01-02 16:20       ` [PATCH] lib: convert two "iterator copy strings" into references David Bremner
2015-01-02 17:52         ` Jani Nikula
2015-01-02 20:07         ` Tomi Ollila
2015-01-03  9:03         ` David Bremner
2014-12-27  8:33 ` [PATCH] lib: collapse computation of directory_id into a single expression David Bremner
2015-01-03 13:30 ` BUG: Using pointer that points to a destructed string's content David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wq56wo78.fsf@nikula.org \
    --to=jani@nikula.org \
    --cc=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).