Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 6A0F2431E82 for ; Sun, 28 Dec 2014 02:45:43 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yneXMn95Pp1K for ; Sun, 28 Dec 2014 02:45:40 -0800 (PST) Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 376F6431FAE for ; Sun, 28 Dec 2014 02:45:40 -0800 (PST) Received: from remotemail by yantan.tethera.net with local (Exim 4.80) (envelope-from ) id 1Y5BLs-0007ep-Jh; Sun, 28 Dec 2014 06:45:36 -0400 Received: (nullmailer pid 12358 invoked by uid 1000); Sun, 28 Dec 2014 10:45:31 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH] lib: another iterator-temporary/stale-pointer bug Date: Sun, 28 Dec 2014 11:45:08 +0100 Message-Id: <1419763508-11902-1-git-send-email-david@tethera.net> X-Mailer: git-send-email 2.1.3 In-Reply-To: <20141226230655.GA41992@pamparam> References: <20141226230655.GA41992@pamparam> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 Dec 2014 10:45:43 -0000 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; /* 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