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

Austin Clements amdragon at MIT.EDU
Thu Dec 22 12:15:53 PST 2011


Quoth David Edmondson on Dec 22 at  7:25 pm:
> On Thu, 22 Dec 2011 14:03:05 -0500, Austin Clements <amdragon at MIT.EDU> wrote:
> > > 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.
> 
> As I said, the principle is sound. What would do in this specific case?
> 
> static void
> handle_sigint (unused (int sig))
> {
>     static char msg[] = "Stopping...         \n";
> 
>     write(2, msg, sizeof(msg)-1);
>     interrupted = 1;
> }
> 
> Just this?
> 
>      if (write(2, msg, sizeof(msg)-1) {
>         /* Appease the compiler. */;
>      }

Maybe I missed something, but what's wrong with using a standard write
loop (like j4ni suggested on IRC)?  In my mind this isn't about
appeasing the compiler; the compiler is pointing out a real bug.
Patch coming in a moment...

I'm not sure what to do about the specific case of fwrite, though
judging by
  http://sourceware.org/bugzilla/show_bug.cgi?id=11959
I'm not the only person who thinks that fwrite being
warn_unused_result is odd.



More information about the notmuch mailing list