public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jim at meyering dot net" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/97817] New: -Wformat-truncation=2 elicits invalid warning Date: Fri, 13 Nov 2020 18:16:53 +0000 [thread overview] Message-ID: <bug-97817-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97817 Bug ID: 97817 Summary: -Wformat-truncation=2 elicits invalid warning Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: jim at meyering dot net Target Milestone: --- Here's the invalid warning. The buffer's size is obviously not 6. It is AT LEAST 6. $ gcc -Wformat-truncation=2 -O2 -c strerror_r.c strerror_r.c: In function ‘strerror_r’: strerror_r.c:12:35: warning: ‘Unknown error ’ directive output truncated writing 14 bytes into a region of size 6 [-Wformat-truncation=] 12 | snprintf (buf, buflen, "Unknown error %d", errnum); | ~~~~~~^~~~~~~~ strerror_r.c:12:5: note: ‘snprintf’ output between 16 and 26 bytes into a destination of size 6 12 | snprintf (buf, buflen, "Unknown error %d", errnum); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here's the reduced test case (from gnulib's strerror.c): $ cat strerror_r.c #define size_t unsigned long long extern int snprintf (char *__restrict __s, size_t __maxlen, const char *__restrict __format, ...) __attribute__ ((__format__ (__printf__, 3, 4))); extern int __xpg_strerror_r (int errnum, char *buf, size_t buflen); int strerror_r (int errnum, char *buf, size_t buflen) { if (buflen <= 5) return 9; int ret = __xpg_strerror_r (errnum, buf, buflen); if (ret == 1 && !*buf) snprintf (buf, buflen, "Unknown error %d", errnum); return ret; }
next reply other threads:[~2020-11-13 18:16 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-11-13 18:16 jim at meyering dot net [this message] 2020-11-13 18:24 ` [Bug c/97817] " jim at meyering dot net 2020-11-13 18:37 ` schwab@linux-m68k.org 2020-11-13 22:36 ` msebor at gcc dot gnu.org 2020-11-13 23:03 ` jim at meyering dot net 2020-11-18 23:16 ` msebor at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-97817-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).