Re: [PATCH] lib: fix warnings when building with clang
authorTomi Ollila <tomi.ollila@iki.fi>
Thu, 29 Nov 2012 14:23:09 +0000 (16:23 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:51:10 +0000 (09:51 -0800)
da/a4013fc84c8e93115e05b9b3fbd1acdb79a702 [new file with mode: 0644]

diff --git a/da/a4013fc84c8e93115e05b9b3fbd1acdb79a702 b/da/a4013fc84c8e93115e05b9b3fbd1acdb79a702
new file mode 100644 (file)
index 0000000..c34877a
--- /dev/null
@@ -0,0 +1,168 @@
+Return-Path: <tomi.ollila@iki.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 63D10431FAF\r
+       for <notmuch@notmuchmail.org>; Thu, 29 Nov 2012 06:23:13 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id ox3NmJXXXAbj for <notmuch@notmuchmail.org>;\r
+       Thu, 29 Nov 2012 06:23:12 -0800 (PST)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id 26627431FAE\r
+       for <notmuch@notmuchmail.org>; Thu, 29 Nov 2012 06:23:12 -0800 (PST)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+       by guru.guru-group.fi (Postfix) with ESMTP id 78A681000E5;\r
+       Thu, 29 Nov 2012 16:23:09 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Jani Nikula <jani@nikula.org>,\r
+       Ethan Glasser-Camp <ethan.glasser.camp@gmail.com>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH] lib: fix warnings when building with clang\r
+In-Reply-To: <m2lieyk25m.fsf@guru.guru-group.fi>\r
+References: <1349076971-2065-1-git-send-email-jani@nikula.org>\r
+       <87pq4c61hc.fsf@betacantrips.com> <87vce3vf5q.fsf@nikula.org>\r
+       <m2lieyk25m.fsf@guru.guru-group.fi>\r
+User-Agent: Notmuch/0.14+116~g29fcdb5 (http://notmuchmail.org) Emacs/24.2.1\r
+       (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+       $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+       !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Thu, 29 Nov 2012 16:23:09 +0200\r
+Message-ID: <m2d2ywh4j6.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 29 Nov 2012 14:23:13 -0000\r
+\r
+On Mon, Oct 22 2012, Tomi Ollila wrote:\r
+\r
+> On Sun, Oct 21 2012, Jani Nikula <jani@nikula.org> wrote:\r
+>\r
+>> On Sun, 21 Oct 2012, Ethan Glasser-Camp <ethan.glasser.camp@gmail.com> wrote:\r
+>>> Jani Nikula <jani@nikula.org> writes:\r
+>>>\r
+>>>> Building notmuch with CC=clang and CXX=clang++ produces the warnings:\r
+>>>>\r
+>>>> CC -O2 lib/tags.o\r
+>>>> lib/tags.c:43:5: warning: expression result unused [-Wunused-value]\r
+>>>>     talloc_steal (tags, list);\r
+>>>>     ^~~~~~~~~~~~~~~~~~~~~~~~~\r
+>>>> /usr/include/talloc.h:345:143: note: expanded from:\r
+>>>>   ...__location__); __talloc_steal_ret; })\r
+>>>>                     ^~~~~~~~~~~~~~~~~~\r
+>>>> 1 warning generated.\r
+>>>>\r
+>>>> CXX -O2 lib/message.o\r
+>>>> lib/message.cc:791:5: warning: expression result unused [-Wunused-value]\r
+>>>>     talloc_reference (message, message->tag_list);\r
+>>>>     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
+>>>> /usr/include/talloc.h:932:36: note: expanded from:\r
+>>>>   ...(_TALLOC_TYPEOF(ptr))_talloc_reference_loc((ctx),(ptr), __location__)\r
+>>>>      ^                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
+>>>> 1 warning generated.\r
+>>>>\r
+>>>> Check talloc_reference() return value, and explicitly ignore\r
+>>>> talloc_steal() return value as it has no failure modes, to silence the\r
+>>>> warnings.\r
+>>>> ---\r
+>>>>  lib/message.cc |    4 +++-\r
+>>>>  lib/tags.c     |    2 +-\r
+>>>>  2 files changed, 4 insertions(+), 2 deletions(-)\r
+>>>>\r
+>>>> diff --git a/lib/message.cc b/lib/message.cc\r
+>>>> index 978de06..320901f 100644\r
+>>>> --- a/lib/message.cc\r
+>>>> +++ b/lib/message.cc\r
+>>>> @@ -788,7 +788,9 @@ notmuch_message_get_tags (notmuch_message_t *message)\r
+>>>>       * possible to modify the message tags (which talloc_unlink's the\r
+>>>>       * current list from the message) while still iterating because\r
+>>>>       * the iterator will keep the current list alive. */\r
+>>>> -    talloc_reference (message, message->tag_list);\r
+>>>> +    if (!talloc_reference (message, message->tag_list))\r
+>>>> + return NULL;\r
+>>>> +\r
+>>>>      return tags;\r
+>>>>  }\r
+>>>\r
+>>> Hi! What you did with talloc_steal is obviously fine. \r
+>>>\r
+>>> I'd be happier about what you did with talloc_reference() if there were\r
+>>> precedent, or a clearly-articulated convention for notmuch. Instead this\r
+>>> is the third use in the codebase that I can see, and the other two are\r
+>>> each unique to themselves. In mime-node.c we print an "out-of-memory"\r
+>>> error and in lib/filenames.c we cast (void) talloc_reference (...), I\r
+>>> guess figuring that we're pretty much hosed anyhow if we run out of\r
+>>> memory.\r
+>>>\r
+>>> Why return NULL here? It seems like if talloc_reference fails, we're\r
+>>> going to crash eventually, so we should print an error to explain our\r
+>>> impending doom. I'd guess you're uneasy printing anything from lib/, but\r
+>>> still want to signal an error, and the only way you can do so is to\r
+>>> return NULL. I guess that silences the compiler warning, but it's not\r
+>>> really the correct way to handle the error IMO. On the other hand, it's\r
+>>> such a weird corner case that I don't even think it merits a FIXME\r
+>>> comment.\r
+>>>\r
+>>> How about an assert instead of a return NULL?\r
+>>\r
+>> No. I don't think a library should assert, exit, or print to stderr on\r
+>> this sort of thing. It's up to the calling application. Even if it\r
+>> probably doesn't have many choices left, given how much memory\r
+>> talloc_reference needs (not much).\r
+>>\r
+>> Ignoring the talloc_reference return value with (void) is just wrong,\r
+>> and the caller of notmuch_message_get_tags should anticipate a NULL\r
+>> return. So IMHO that's the pragmatic thing to do in this mostly\r
+>> theoretical situation, the biggest change being silencing the warning.\r
+>\r
+> I agree that the best library can do is to return NULL (if talloc had\r
+> a place in ctx to store error indication that could be used but I did\r
+> not see any in quick look -- and using global there is not a good idea)\r
+>\r
+> but, before returning NULL should 'tags' be freed.\r
+\r
+Ah, this is talloc() stuff, so the patch is good in this part.\r
+\r
+> Additionally, should lib/filenames.c be changed to have code:\r
+>\r
+> if (unlikely (talloc_reference(filenames, list) == NULL)) {\r
+>     talloc_free (filenames);\r
+>     return NULL;\r
+> }\r
+\r
+More like \r
+\r
+if (unlikely (talloc_reference(filenames, list) == NULL))\r
+    return NULL;\r
+\r
+But that is out of scope of this patch...\r
+\r
+\r
+so, +1\r
+\r
+Tomi\r
+\r
+>> BR,\r
+>> Jani.\r
+>\r
+> (btw, what are the chances that program crashes before returning NULL\r
+> due to page fault in stack frame allocation ???)\r
+>\r
+> Tomi\r