[RFC][PATCH] notmuch: Workaround to allow ignoring non-void function return.

Austin Clements amdragon at MIT.EDU
Thu Dec 22 11:03:05 PST 2011


Quoth David Edmondson on Dec 22 at  7:21 am:
> On Thu, 22 Dec 2011 02:03:45 -0500, Austin Clements <amdragon at MIT.EDU> wrote:
> > I must admit I haven't been following the warnings problem very
> > closely, but perhaps we shouldn't be ignoring these return codes?
> 
> In general I agree, but what would we do if writing an error message to
> stderr fails?

This was discussed on IRC, but calls to write(2) should never be bare.
I believe it's marked warn_unused_result not because libc is so
concerned with people checking for error returns (otherwise all sorts
of things would be marked warn_unused_result) but because even a
successful write can be a short write.  Hence, not checking the result
is a bug, even if you don't care about errors.

fwrite's a little trickier, since it will only short-write on an
error, so to me it seems perfectly legitimate to ignore the result if
you don't care about errors.

I don't seem to have whatever glibc version the buildbot does that
marks these warn_unused_result, but I can reproduce it by adding

__attribute__((warn_unused_result))
ssize_t write(int fd, const void *buf, size_t count);
__attribute__((warn_unused_result))
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);

to notmuch-client.h.  Testing with these, if I add any form of result
checking, even if it does nothing in most cases, GCC is quiet.


More information about the notmuch mailing list