[Bug middle-end/88251] -Wformat-truncation=2 false alarms when compiling gzip, Emacs
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Nov 28 20:07:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88251
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
Status|UNCONFIRMED |RESOLVED
CC| |msebor at gcc dot gnu.org
Resolution|--- |INVALID
--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The warning in this case is by design. The test makes it clear that the buffer
can be as small as 2 bytes but the output is at least 15. With
-Wformat-truncation=2 the buffer needs to be big enough for the longest output,
or 25 + 1 bytes. This suppresses the warning:
int
rpl_strerror_r (int errnum, char *buf, size_t buflen)
{
if (buflen <= 25)
return 34;
return snprintf (buf, buflen, "Unknown error %d", errnum);
}
More information about the Gcc-bugs
mailing list