Re: [PATCH] lib: fix warnings when building with clang
authorEthan Glasser-Camp <ethan.glasser.camp@gmail.com>
Sun, 21 Oct 2012 01:46:39 +0000 (21:46 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:49:55 +0000 (09:49 -0800)
66/94d36309a79bfce9bb86802d5e28bbcc487c8d [new file with mode: 0644]

diff --git a/66/94d36309a79bfce9bb86802d5e28bbcc487c8d b/66/94d36309a79bfce9bb86802d5e28bbcc487c8d
new file mode 100644 (file)
index 0000000..cd08f27
--- /dev/null
@@ -0,0 +1,132 @@
+Return-Path: <ethan.glasser.camp@gmail.com>\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 543AE431FAF\r
+       for <notmuch@notmuchmail.org>; Sat, 20 Oct 2012 18:46:45 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] 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 XDU51ezOWXJZ for <notmuch@notmuchmail.org>;\r
+       Sat, 20 Oct 2012 18:46:44 -0700 (PDT)\r
+Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com\r
+       [209.85.220.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 9405C431FAE\r
+       for <notmuch@notmuchmail.org>; Sat, 20 Oct 2012 18:46:44 -0700 (PDT)\r
+Received: by mail-vc0-f181.google.com with SMTP id n11so1909718vch.26\r
+       for <notmuch@notmuchmail.org>; Sat, 20 Oct 2012 18:46:42 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:subject:in-reply-to:references:user-agent:date:message-id\r
+       :mime-version:content-type;\r
+       bh=im1CbZ8uFOgVenJY3mO7AtoSAq28Pgp+cjOV+l2zAhQ=;\r
+       b=nVNIiHE8ZLfgVINsPs1Ggnpjv4llZQv/2HLzjbZ1ziUnlolEt4ZCHHbgjtMY+Y0aFE\r
+       0inYfK0YITIaUnteBL7iUmwxeDnx+g+p48BFzXliG78+ZDbl29oSNv8k/eRLMppPIuLH\r
+       YMUdo3j8eXdSpWKf2P9xHWSWQ4sF1FPpiN9vXx54pcJbdbvAvFuv25LyTmfD7B+IOwY5\r
+       2ui8wRysOVk9jME+DZ7/TFtJ8sBlvCtw2HgAK/LIOaF4ilIlSMHQQNwM5Ru8Iif79teD\r
+       Ra2C/0U+4e85eArjNcepwMiBiMTVcjgbqlX8vXG591qiUcIZOU4g6syLHpX4/CfgWvm3\r
+       NWrg==\r
+Received: by 10.220.220.5 with SMTP id hw5mr8024596vcb.53.1350784002732;\r
+       Sat, 20 Oct 2012 18:46:42 -0700 (PDT)\r
+Received: from smtp.gmail.com (p70-80.acedsl.com. [66.114.70.80])\r
+       by mx.google.com with ESMTPS id y15sm6004289vdt.9.2012.10.20.18.46.40\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Sat, 20 Oct 2012 18:46:41 -0700 (PDT)\r
+From: Ethan Glasser-Camp <ethan.glasser.camp@gmail.com>\r
+To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH] lib: fix warnings when building with clang\r
+In-Reply-To: <1349076971-2065-1-git-send-email-jani@nikula.org>\r
+References: <1349076971-2065-1-git-send-email-jani@nikula.org>\r
+User-Agent: Notmuch/0.14+45~g6ea9330 (http://notmuchmail.org) Emacs/23.3.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Sat, 20 Oct 2012 21:46:39 -0400\r
+Message-ID: <87pq4c61hc.fsf@betacantrips.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\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: Sun, 21 Oct 2012 01:46:45 -0000\r
+\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
+Ethan\r