Bug 11959

Summary: fwrite must not be declared with the warn_unused_result attribute
Product: glibc Reporter: jim <jim>
Component: stdioAssignee: Ulrich Drepper <drepper.fsp>
Status: RESOLVED FIXED    
Severity: normal CC: aj, andrey.vihrov, eblake, glibc-bugs, jrnieder
Priority: P2 Flags: fweimer: security-
Version: 2.13   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:
Attachments: remove fwrite's __wur attribute

Description jim@meyering.net 2010-08-30 20:29:38 UTC
The use of the warn_unused_result attribute in the declaration of fwrite is
undesirable, since it is perfectly legitimate to use fwrite without inspecting
its return value.  In that case, one can still detect failure via ferror.
That libc declares fwrite with this attribute causes inordinate trouble for
those who try to avoid gcc warnings about this attribute.

Patch below.
Comment 1 jim@meyering.net 2010-08-30 20:32:58 UTC
Created attachment 4956 [details]
remove fwrite's __wur attribute
Comment 2 Eric Blake 2010-08-30 20:46:01 UTC
This is particularly true since fputc is declared without __wur - consistency
demands that both or neither should have the attribute, and I strongly favor
neither based on the number of bug reports that have been falsely attributed to
gnulib as a result of glibc's header markup on fwrite.  For example:
http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/22751
Comment 3 Eric Blake 2010-08-30 21:11:04 UTC
See also this gcc bug:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509
where the suggested hammer is to completely disable ALL warn_unused_result
checking in order to silence spurious warnings for fwrite().  I'd rather remove
the __wur from fwrite than turn off what would otherwise be a useful gcc feature
for functions where warning really does make sense.
Comment 4 Andreas Jaeger 2012-04-11 19:04:35 UTC
Thanks, your patch has been added to git.
Comment 5 Jackie Rosen 2014-02-16 19:42:48 UTC Comment hidden (spam)