From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 543AE431FAF for ; Sat, 20 Oct 2012 18:46:45 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XDU51ezOWXJZ for ; Sat, 20 Oct 2012 18:46:44 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 9405C431FAE for ; Sat, 20 Oct 2012 18:46:44 -0700 (PDT) Received: by mail-vc0-f181.google.com with SMTP id n11so1909718vch.26 for ; Sat, 20 Oct 2012 18:46:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:in-reply-to:references:user-agent:date:message-id :mime-version:content-type; bh=im1CbZ8uFOgVenJY3mO7AtoSAq28Pgp+cjOV+l2zAhQ=; b=nVNIiHE8ZLfgVINsPs1Ggnpjv4llZQv/2HLzjbZ1ziUnlolEt4ZCHHbgjtMY+Y0aFE 0inYfK0YITIaUnteBL7iUmwxeDnx+g+p48BFzXliG78+ZDbl29oSNv8k/eRLMppPIuLH YMUdo3j8eXdSpWKf2P9xHWSWQ4sF1FPpiN9vXx54pcJbdbvAvFuv25LyTmfD7B+IOwY5 2ui8wRysOVk9jME+DZ7/TFtJ8sBlvCtw2HgAK/LIOaF4ilIlSMHQQNwM5Ru8Iif79teD Ra2C/0U+4e85eArjNcepwMiBiMTVcjgbqlX8vXG591qiUcIZOU4g6syLHpX4/CfgWvm3 NWrg== Received: by 10.220.220.5 with SMTP id hw5mr8024596vcb.53.1350784002732; Sat, 20 Oct 2012 18:46:42 -0700 (PDT) Received: from smtp.gmail.com (p70-80.acedsl.com. [66.114.70.80]) by mx.google.com with ESMTPS id y15sm6004289vdt.9.2012.10.20.18.46.40 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 20 Oct 2012 18:46:41 -0700 (PDT) From: Ethan Glasser-Camp To: Jani Nikula , notmuch@notmuchmail.org Subject: Re: [PATCH] lib: fix warnings when building with clang In-Reply-To: <1349076971-2065-1-git-send-email-jani@nikula.org> References: <1349076971-2065-1-git-send-email-jani@nikula.org> User-Agent: Notmuch/0.14+45~g6ea9330 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Sat, 20 Oct 2012 21:46:39 -0400 Message-ID: <87pq4c61hc.fsf@betacantrips.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Oct 2012 01:46:45 -0000 Jani Nikula writes: > Building notmuch with CC=clang and CXX=clang++ produces the warnings: > > CC -O2 lib/tags.o > lib/tags.c:43:5: warning: expression result unused [-Wunused-value] > talloc_steal (tags, list); > ^~~~~~~~~~~~~~~~~~~~~~~~~ > /usr/include/talloc.h:345:143: note: expanded from: > ...__location__); __talloc_steal_ret; }) > ^~~~~~~~~~~~~~~~~~ > 1 warning generated. > > CXX -O2 lib/message.o > lib/message.cc:791:5: warning: expression result unused [-Wunused-value] > talloc_reference (message, message->tag_list); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > /usr/include/talloc.h:932:36: note: expanded from: > ...(_TALLOC_TYPEOF(ptr))_talloc_reference_loc((ctx),(ptr), __location__) > ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 1 warning generated. > > Check talloc_reference() return value, and explicitly ignore > talloc_steal() return value as it has no failure modes, to silence the > warnings. > --- > lib/message.cc | 4 +++- > lib/tags.c | 2 +- > 2 files changed, 4 insertions(+), 2 deletions(-) > > diff --git a/lib/message.cc b/lib/message.cc > index 978de06..320901f 100644 > --- a/lib/message.cc > +++ b/lib/message.cc > @@ -788,7 +788,9 @@ notmuch_message_get_tags (notmuch_message_t *message) > * possible to modify the message tags (which talloc_unlink's the > * current list from the message) while still iterating because > * the iterator will keep the current list alive. */ > - talloc_reference (message, message->tag_list); > + if (!talloc_reference (message, message->tag_list)) > + return NULL; > + > return tags; > } Hi! What you did with talloc_steal is obviously fine. I'd be happier about what you did with talloc_reference() if there were precedent, or a clearly-articulated convention for notmuch. Instead this is the third use in the codebase that I can see, and the other two are each unique to themselves. In mime-node.c we print an "out-of-memory" error and in lib/filenames.c we cast (void) talloc_reference (...), I guess figuring that we're pretty much hosed anyhow if we run out of memory. Why return NULL here? It seems like if talloc_reference fails, we're going to crash eventually, so we should print an error to explain our impending doom. I'd guess you're uneasy printing anything from lib/, but still want to signal an error, and the only way you can do so is to return NULL. I guess that silences the compiler warning, but it's not really the correct way to handle the error IMO. On the other hand, it's such a weird corner case that I don't even think it merits a FIXME comment. How about an assert instead of a return NULL? Ethan