public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "torsten.mandel at sap dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/114374] New: [12/13 Regression] snprintf Wformat-truncation Date: Mon, 18 Mar 2024 08:29:05 +0000 [thread overview] Message-ID: <bug-114374-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114374 Bug ID: 114374 Summary: [12/13 Regression] snprintf Wformat-truncation Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: torsten.mandel at sap dot com Target Milestone: --- Source: // =========================================== #include "stdio.h" int main() { char buf[11]; int loop(1); do { snprintf(buf,sizeof(buf),"%d",loop++); } while(true); } // =========================================== Compiled with: gcc -Wall triggers: ./buffertest.cpp: In function ‘int main()’: ./buffertest.cpp:8:37: warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=] 8 | snprintf(buf,sizeof(buf),"%d",loop++); | ^ ./buffertest.cpp:8:17: note: ‘snprintf’ output between 2 and 12 bytes into a destination of size 11 8 | snprintf(buf,sizeof(buf),"%d",loop++); | ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ when using gcc-12 and gcc-13; gcc-11 compiled without error. Replacing loop++ with ++loop does not trigger the error; neither case should be an error as the overflow is UB in both cases and only positive numbers should be considered regarding the target buffer size.
next reply other threads:[~2024-03-18 8:29 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-03-18 8:29 torsten.mandel at sap dot com [this message] 2024-03-18 9:25 ` [Bug tree-optimization/114374] [12/13/14 " rguenth at gcc dot gnu.org 2024-03-18 9:29 ` torsten.mandel at sap dot com 2024-03-18 9:36 ` torsten.mandel at sap dot com 2024-03-18 9:37 ` torsten.mandel at sap dot com 2024-03-18 16:08 ` pinskia at gcc dot gnu.org 2024-03-19 11:31 ` jakub at gcc dot gnu.org 2024-03-19 11:45 ` jakub at gcc dot gnu.org 2024-03-22 13:30 ` law 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-114374-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).