On Sun, Apr 30, 2017 at 7:23 PM, Martin Sebor <mse...@gmail.com> wrote:
> The warning is triggered by the fscanf function being decorated
> with attribute warn_unused_result in the <stdio.h> header.  The
> header is part of libc, not GCC, so the appropriate place to
> raise a concern with it would on the libc mailing list (such as
> libc-help or libc-alpha for Glibc).

I see, sorry if this should have been the wrong place for this discussion.

> If you find the -Wunused-result warnings unhelpful you should be
> able to disable them by -Wno-unused-result, either on the command
> line or by adding pragma GCC diagnostic ignored "-Wno-unused-result"
> above the call.  The warnings can also be suppressed simply by
> testing the return value and doing nothing with it (e.g., by
> 'if (fscanf(fh, "%u", &value)) { /* do nothing */ }').

Yeah, that is what I did in the end. Since fortification is only
enabled (by default) when building the Debian package, I added
-Wno-unused-result in debian/rules. Still I don't think that it is
sensible to have fortification, which I generally think makes sense
for its runtime buffer overflow protection, cause these overeager
compiler warnings, in the first place. Not to mention that compiling
with -Wno-unused-result might not only silence unused-result warnings
triggered by fortification, though I rather live with this limitation
than spreading boilerplate across my code.

> The answer obviously depends on what relies on the integrity
> of the output, but I'm not sure I see how the question is
> relevant to the examples above (it's fscanf that's decorated
> with warn_unused_result, not fprintf).  There is no warning
> for printf/fprintf calls whose return value is unused,
> precisely because it is commonly ignored.

This example, was just an example. But as I said, with fortification
enabled, it seems most IO functions, cause unused-result warnings,
perhaps not printf(), but write() and read() are effected as well.

Sebastian

Reply via email to