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