https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71501
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Known to fail| |4.8.5, 4.9.4, 5.4.0, 6.4.0, | |7.3.0, 8.2.0, 9.0 --- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> --- GCC 8 and 9 detect the unterminated strncpy call but not yet passing the result to printf. I'm hoping to do it in GCC 10. $ gcc -O2 -S -Wall pr71501.c pr71501.c: In function ‘main’: pr71501.c:7:9: warning: unused variable ‘n’ [-Wunused-variable] char *n = "12345"; ^ pr71501.c:9:3: warning: ‘strncpy’ output truncated before terminating nul copying 5 bytes from a string of the same length [-Wstringop-truncation] strncpy(c, "12345", 5); ^~~~~~~~~~~~~~~~~~~~~~ GCC 9 detects some very simple cases of passing unterminated arrays to printf: $ cat z.c && gcc -O2 -S -Wall z.c const char a[] = { '1', '2', '3' }; void f (void) { __builtin_printf ("%s", a); } z.c: In function ‘f’: z.c:5:22: warning: ‘%s’ directive argument is not a nul-terminated string [-Wformat-overflow=] 5 | __builtin_printf ("%s", a); | ^~ ~ z.c:1:12: note: referenced argument declared here 1 | const char a[] = { '1', '2', '3' }; | ^