Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / f0 / db720e680c462d2cad1417773d2ce7550002df
1 Return-Path: <tomi.ollila@iki.fi>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 41F9F431FB6\r
6         for <notmuch@notmuchmail.org>; Thu,  2 May 2013 03:01:54 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id Bq6-9iWzF6Ui for <notmuch@notmuchmail.org>;\r
16         Thu,  2 May 2013 03:01:50 -0700 (PDT)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id 9C103431FAF\r
19         for <notmuch@notmuchmail.org>; Thu,  2 May 2013 03:01:50 -0700 (PDT)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id 336B5100044;\r
22         Thu,  2 May 2013 13:01:48 +0300 (EEST)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: Vladimir.Marek@oracle.com, notmuch@notmuchmail.org\r
25 Subject: Re: [PATCH 01/24] lib/message.cc: stale pointer bug\r
26 In-Reply-To: <1367444021-2757-1-git-send-email-Vladimir.Marek@oracle.com>\r
27 References: <1367444021-2757-1-git-send-email-Vladimir.Marek@oracle.com>\r
28 User-Agent: Notmuch/0.15.2+75~gd7fa7c4 (http://notmuchmail.org) Emacs/24.3.1\r
29         (x86_64-unknown-linux-gnu)\r
30 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
31         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
32         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
33 Date: Thu, 02 May 2013 13:01:47 +0300\r
34 Message-ID: <m2sj25snsk.fsf@guru.guru-group.fi>\r
35 MIME-Version: 1.0\r
36 Content-Type: text/plain\r
37 Cc: Vladimir Marek <vlmarek@volny.cz>\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Thu, 02 May 2013 10:01:54 -0000\r
51 \r
52 On Thu, May 02 2013, Vladimir.Marek@oracle.com wrote:\r
53 \r
54 > From: Vladimir Marek <vlmarek@volny.cz>\r
55 >\r
56 > Xapian::TermIterator::operator* returns std::string which is destroyed\r
57 > as soon as (*i).c_str() finishes. The remembered pointer 'term' then\r
58 > references invalid memory.\r
59 \r
60 Looks to me like a good solution...\r
61 \r
62 \r
63 Tomi\r
64 \r
65 >\r
66 > Signed-off-by: Vladimir Marek <vlmarek@volny.cz>\r
67 > ---\r
68 >  lib/message.cc |   11 ++++++-----\r
69 >  1 file changed, 6 insertions(+), 5 deletions(-)\r
70 >\r
71 > diff --git a/lib/message.cc b/lib/message.cc\r
72 > index 8720c1b..a890550 100644\r
73 > --- a/lib/message.cc\r
74 > +++ b/lib/message.cc\r
75 > @@ -266,18 +266,19 @@ _notmuch_message_get_term (notmuch_message_t *message,\r
76 >                          const char *prefix)\r
77 >  {\r
78 >      int prefix_len = strlen (prefix);\r
79 > -    const char *term = NULL;\r
80 > +    std::string term;\r
81 >      char *value;\r
82 >  \r
83 >      i.skip_to (prefix);\r
84 >  \r
85 > -    if (i != end)\r
86 > -     term = (*i).c_str ();\r
87 > +    if (i == end)\r
88 > +     return NULL;\r
89 >  \r
90 > -    if (!term || strncmp (term, prefix, prefix_len))\r
91 > +    term = *i;\r
92 \r
93 ... hmm, a raii(?) solution above would be std::string term = *i;\r
94 \r
95 > +    if (strncmp (term.c_str(), prefix, prefix_len))\r
96 >       return NULL;\r
97 >  \r
98 > -    value = talloc_strdup (message, term + prefix_len);\r
99 > +    value = talloc_strdup (message, term.c_str() + prefix_len);\r
100 >  \r
101 >  #if DEBUG_DATABASE_SANITY\r
102 >      i++;\r
103 > -- \r
104 > 1.7.9.2\r
105 >\r
106 > _______________________________________________\r
107 > notmuch mailing list\r
108 > notmuch@notmuchmail.org\r
109 > http://notmuchmail.org/mailman/listinfo/notmuch\r