https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105080
Bug ID: 105080 Summary: Bugus -Wformat-truncation Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: marcandre.lureau at gmail dot com Target Milestone: --- With Fedora gcc-12.0.1-0.12.fc36.x86_64 gcc (GCC) 12.0.1 20220308 (Red Hat 12.0.1-0) test.c: #include <stdio.h> void main(void) { char foo[3]; int i; for (i = 0; i < 16; i++) { snprintf(foo, sizeof(foo), "%d", i); } } $ gcc -Wformat-truncation test.c test.c: In function ‘main’: test.c:9:45: warning: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 3 [-Wformat-truncation=] 9 | snprintf(foo, sizeof(foo), "%d", i); | ^~ test.c:9:44: note: directive argument in the range [-2147483647, 15] 9 | snprintf(foo, sizeof(foo), "%d", i); | ^~~~ test.c:9:17: note: ‘snprintf’ output between 2 and 12 bytes into a destination of size 3 9 | snprintf(foo, sizeof(foo), "%d", i); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The computed range seems incorrect. There are similar variants of this bug that have been found while compiling QEMU (https://patchew.org/QEMU/20220328084717.367993-1-marcandre.lur...@redhat.com/)