https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87096
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |wrong-code Status|UNCONFIRMED |NEW Last reconfirmed| |2018-08-24 CC| |msebor at gcc dot gnu.org Ever confirmed|0 |1 Known to fail| |4.7.4, 5.3.0, 6.4.0, 7.3.0, | |8.1.0, 9.0 --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- Confirmed. This goes back to the original folding of snprintf to memcpy. $ cat f.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout f.c int f (char *d) { return __builtin_snprintf (d, __INT_MAX__ + 1LLU, ""); } f.c: In function ‘f’: f.c:3:53: warning: zero-length gnu_printf format string [-Wformat-zero-length] return __builtin_snprintf (d, __INT_MAX__ + 1LLU, ""); ^~ ;; Function f (f, funcdef_no=0, decl_uid=1756, cgraph_uid=0, symbol_order=0) f (char * d) { <bb 2>: __builtin_memcpy (d_2(D), "", 1); return 0; } GCC 8 warns on this case but still folds it into memcpy and return 0. f.c:3:10: warning: specified bound 2147483648 exceeds ‘INT_MAX’ [-Wformat-truncation=] return __builtin_snprintf (d, __INT_MAX__ + 1LLU, ""); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~