[Bug c/80354] Poor support to silence -Wformat-truncation=1

msharov at users dot sourceforge.net gcc-bugzilla@gcc.gnu.org
Wed May 9 23:04:00 GMT 2018


--- Comment #9 from Mike Sharov <msharov at users dot sourceforge.net> ---
(In reply to Martin Sebor from comment #8)
> A simple way to avoid the warning while also avoiding bugs resulting from
> unhandled truncation is to detect it and abort if it happens, e.g.

First of all, you might want to mention this in the error message. The way it
is presently worded gives the impression that the only way to remove the
warning is to increase the buffer size. I guarantee you that most people will
just turn off the warning in this case. And then come here to complain, because
the kind of warning that is wrong in most cases (if only in our opinion) should
not be in -Wall.

Secondly, this is precisely the annoying part about it: you are making the
decision that allowing truncation to happen is always a bug and forcing it to
be handled as one. I do not consider it a problem to pass a truncated filename
to open and having it fail there. There are, naturally, some cases where this
could cause a security problem, but I am the one who should determine whether
each particular snprintf is one of those cases, and consequently I should also
have the option to tell the compiler that it is not. If I was ok with bloating
my program due to an excessive concern with safety, I'd be using Java, not C.

More information about the Gcc-bugs mailing list