]> rtime.felk.cvut.cz Git - notmuch.git/commitdiff
lib: another iterator-temporary/stale-pointer bug
authorDavid Bremner <david@tethera.net>
Sun, 28 Dec 2014 10:45:08 +0000 (11:45 +0100)
committerDavid Bremner <david@tethera.net>
Fri, 2 Jan 2015 16:10:37 +0000 (17:10 +0100)
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

lib/message.cc

index a7a13cc26aa181ec94f336048385403b903d4d37..bacb4d46a0c1aa336a91e3b76b65097b1b1884c5 100644 (file)
@@ -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);