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 63D10431FAF
\r
6 for <notmuch@notmuchmail.org>; Thu, 29 Nov 2012 06:23:13 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 ox3NmJXXXAbj for <notmuch@notmuchmail.org>;
\r
16 Thu, 29 Nov 2012 06:23:12 -0800 (PST)
\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 26627431FAE
\r
19 for <notmuch@notmuchmail.org>; Thu, 29 Nov 2012 06:23:12 -0800 (PST)
\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])
\r
21 by guru.guru-group.fi (Postfix) with ESMTP id 78A681000E5;
\r
22 Thu, 29 Nov 2012 16:23:09 +0200 (EET)
\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
24 To: Jani Nikula <jani@nikula.org>,
\r
25 Ethan Glasser-Camp <ethan.glasser.camp@gmail.com>, notmuch@notmuchmail.org
\r
26 Subject: Re: [PATCH] lib: fix warnings when building with clang
\r
27 In-Reply-To: <m2lieyk25m.fsf@guru.guru-group.fi>
\r
28 References: <1349076971-2065-1-git-send-email-jani@nikula.org>
\r
29 <87pq4c61hc.fsf@betacantrips.com> <87vce3vf5q.fsf@nikula.org>
\r
30 <m2lieyk25m.fsf@guru.guru-group.fi>
\r
31 User-Agent: Notmuch/0.14+116~g29fcdb5 (http://notmuchmail.org) Emacs/24.2.1
\r
32 (x86_64-unknown-linux-gnu)
\r
33 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL
\r
34 $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F
\r
35 !)g;OY^,BjTbr)Np:%c_o'jj,Z
\r
36 Date: Thu, 29 Nov 2012 16:23:09 +0200
\r
37 Message-ID: <m2d2ywh4j6.fsf@guru.guru-group.fi>
\r
39 Content-Type: text/plain
\r
40 X-BeenThere: notmuch@notmuchmail.org
\r
41 X-Mailman-Version: 2.1.13
\r
43 List-Id: "Use and development of the notmuch mail system."
\r
44 <notmuch.notmuchmail.org>
\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
46 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
48 List-Post: <mailto:notmuch@notmuchmail.org>
\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
51 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
52 X-List-Received-Date: Thu, 29 Nov 2012 14:23:13 -0000
\r
54 On Mon, Oct 22 2012, Tomi Ollila wrote:
\r
56 > On Sun, Oct 21 2012, Jani Nikula <jani@nikula.org> wrote:
\r
58 >> On Sun, 21 Oct 2012, Ethan Glasser-Camp <ethan.glasser.camp@gmail.com> wrote:
\r
59 >>> Jani Nikula <jani@nikula.org> writes:
\r
61 >>>> Building notmuch with CC=clang and CXX=clang++ produces the warnings:
\r
63 >>>> CC -O2 lib/tags.o
\r
64 >>>> lib/tags.c:43:5: warning: expression result unused [-Wunused-value]
\r
65 >>>> talloc_steal (tags, list);
\r
66 >>>> ^~~~~~~~~~~~~~~~~~~~~~~~~
\r
67 >>>> /usr/include/talloc.h:345:143: note: expanded from:
\r
68 >>>> ...__location__); __talloc_steal_ret; })
\r
69 >>>> ^~~~~~~~~~~~~~~~~~
\r
70 >>>> 1 warning generated.
\r
72 >>>> CXX -O2 lib/message.o
\r
73 >>>> lib/message.cc:791:5: warning: expression result unused [-Wunused-value]
\r
74 >>>> talloc_reference (message, message->tag_list);
\r
75 >>>> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\r
76 >>>> /usr/include/talloc.h:932:36: note: expanded from:
\r
77 >>>> ...(_TALLOC_TYPEOF(ptr))_talloc_reference_loc((ctx),(ptr), __location__)
\r
78 >>>> ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\r
79 >>>> 1 warning generated.
\r
81 >>>> Check talloc_reference() return value, and explicitly ignore
\r
82 >>>> talloc_steal() return value as it has no failure modes, to silence the
\r
85 >>>> lib/message.cc | 4 +++-
\r
86 >>>> lib/tags.c | 2 +-
\r
87 >>>> 2 files changed, 4 insertions(+), 2 deletions(-)
\r
89 >>>> diff --git a/lib/message.cc b/lib/message.cc
\r
90 >>>> index 978de06..320901f 100644
\r
91 >>>> --- a/lib/message.cc
\r
92 >>>> +++ b/lib/message.cc
\r
93 >>>> @@ -788,7 +788,9 @@ notmuch_message_get_tags (notmuch_message_t *message)
\r
94 >>>> * possible to modify the message tags (which talloc_unlink's the
\r
95 >>>> * current list from the message) while still iterating because
\r
96 >>>> * the iterator will keep the current list alive. */
\r
97 >>>> - talloc_reference (message, message->tag_list);
\r
98 >>>> + if (!talloc_reference (message, message->tag_list))
\r
104 >>> Hi! What you did with talloc_steal is obviously fine.
\r
106 >>> I'd be happier about what you did with talloc_reference() if there were
\r
107 >>> precedent, or a clearly-articulated convention for notmuch. Instead this
\r
108 >>> is the third use in the codebase that I can see, and the other two are
\r
109 >>> each unique to themselves. In mime-node.c we print an "out-of-memory"
\r
110 >>> error and in lib/filenames.c we cast (void) talloc_reference (...), I
\r
111 >>> guess figuring that we're pretty much hosed anyhow if we run out of
\r
114 >>> Why return NULL here? It seems like if talloc_reference fails, we're
\r
115 >>> going to crash eventually, so we should print an error to explain our
\r
116 >>> impending doom. I'd guess you're uneasy printing anything from lib/, but
\r
117 >>> still want to signal an error, and the only way you can do so is to
\r
118 >>> return NULL. I guess that silences the compiler warning, but it's not
\r
119 >>> really the correct way to handle the error IMO. On the other hand, it's
\r
120 >>> such a weird corner case that I don't even think it merits a FIXME
\r
123 >>> How about an assert instead of a return NULL?
\r
125 >> No. I don't think a library should assert, exit, or print to stderr on
\r
126 >> this sort of thing. It's up to the calling application. Even if it
\r
127 >> probably doesn't have many choices left, given how much memory
\r
128 >> talloc_reference needs (not much).
\r
130 >> Ignoring the talloc_reference return value with (void) is just wrong,
\r
131 >> and the caller of notmuch_message_get_tags should anticipate a NULL
\r
132 >> return. So IMHO that's the pragmatic thing to do in this mostly
\r
133 >> theoretical situation, the biggest change being silencing the warning.
\r
135 > I agree that the best library can do is to return NULL (if talloc had
\r
136 > a place in ctx to store error indication that could be used but I did
\r
137 > not see any in quick look -- and using global there is not a good idea)
\r
139 > but, before returning NULL should 'tags' be freed.
\r
141 Ah, this is talloc() stuff, so the patch is good in this part.
\r
143 > Additionally, should lib/filenames.c be changed to have code:
\r
145 > if (unlikely (talloc_reference(filenames, list) == NULL)) {
\r
146 > talloc_free (filenames);
\r
152 if (unlikely (talloc_reference(filenames, list) == NULL))
\r
155 But that is out of scope of this patch...
\r
165 > (btw, what are the chances that program crashes before returning NULL
\r
166 > due to page fault in stack frame allocation ???)
\r