https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90036
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Known to work| |7.3.0 Keywords| |diagnostic Last reconfirmed| |2019-04-10 CC| |msebor at gcc dot gnu.org Blocks| |85741 Ever confirmed|0 |1 Summary|False positive: directive |[8/9 Regression] false |argument is null |positive: directive |[-Werror=format-overflow=] |argument is null | |[-Werror=format-overflow=] Known to fail| |8.3.0, 9.0 --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- (When reporting bugs we ask for a test case. Please see https://www.gnu.org/software/gcc/bugs). That said, I can reproduce the warning with the top of trunk and with GCC 8. The reason why the warning is issued for sprintf and not for strlen is because it is implemented differently between the two functions (it runs on different IL). The null in the IL is the result of the jump threading optimization. The warning can be suppressed by adding 'assert (vstring)' just above the sprintf call. Here's the IL the warning code sees: stab_start_class_type (void * p, const char * tag, unsigned int id, bfd_boolean structp, unsigned int size, bfd_boolean vptr, bfd_boolean ownvptr) { ... <bb 8> [local count: 237404318]: if (ownvptr_24(D) != 0) goto <bb 9>; [100.00%] else goto <bb 15>; [0.00%] ... <bb 15> [local count: 0]: _51 = strlen (0B); _59 = _51 + 3; vtable_16 = xmalloc (_59); sprintf (vtable_16, "~%%%s", 0B); _18 = MEM[(struct stab_write_handle *)p_22(D)].type_stack; _18->vtable = vtable_16; goto <bb 14>; [100.00%] } Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85741 [Bug 85741] [meta-bug] bogus/missing -Wformat-overflow