public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "lavr at ncbi dot nlm.nih.gov" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/100401] New: Bogus -Wformat-overflow warning Date: Mon, 03 May 2021 16:58:53 +0000 [thread overview] Message-ID: <bug-100401-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100401 Bug ID: 100401 Summary: Bogus -Wformat-overflow warning Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: lavr at ncbi dot nlm.nih.gov Target Milestone: --- $ gcc --version gcc (GCC) 10.2.0 $ cat bogus.c #include <stdio.h> #define RECLEN 128 struct S { int code; char text[0]; }; const void fun(int n) { union { struct S s; char rec[RECLEN]; } x; const char* err; if (!n) { err = "No error"; } else { sprintf(x.s.text, "Error %d", n); err = x.s.text; } printf("%s\n", err); } int main(int argc, const char* argv[]) { fun(argc); return 0; } $ gcc -Wall -O2 bogus.c bogus.c: In function ‘fun’: bogus.c:22:28: warning: ‘Error ’ directive writing 6 bytes into a region of size 0 [-Wformat-overflow=] 22 | sprintf(x.s.text, "Error %d", n); | ^~~~~~ bogus.c:22:9: note: ‘sprintf’ output between 8 and 18 bytes into a destination of size 0 22 | sprintf(x.s.text, "Error %d", n); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
next reply other threads:[~2021-05-03 16:58 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-05-03 16:58 lavr at ncbi dot nlm.nih.gov [this message] 2021-05-03 19:30 ` [Bug middle-end/100401] Bogus -Wformat-overflow for a trailing zero-length array of a union msebor at gcc dot gnu.org 2021-05-03 20:09 ` lavr at ncbi dot nlm.nih.gov
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-100401-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).