unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Ethan Glasser-Camp <ethan.glasser.camp@gmail.com>
To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org
Subject: Re: [PATCH] lib: fix warnings when building with clang
Date: Sat, 20 Oct 2012 21:46:39 -0400	[thread overview]
Message-ID: <87pq4c61hc.fsf@betacantrips.com> (raw)
In-Reply-To: <1349076971-2065-1-git-send-email-jani@nikula.org>

Jani Nikula <jani@nikula.org> 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

  reply	other threads:[~2012-10-21  1:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-01  7:36 [PATCH] lib: fix warnings when building with clang Jani Nikula
2012-10-21  1:46 ` Ethan Glasser-Camp [this message]
2012-10-21 18:44   ` Jani Nikula
2012-10-22 14:32     ` Tomi Ollila
2012-11-29 14:23       ` Tomi Ollila
2012-12-01 12:43 ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pq4c61hc.fsf@betacantrips.com \
    --to=ethan.glasser.camp@gmail.com \
    --cc=jani@nikula.org \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).