https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104119

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
            Summary|Wrong                       |unexpected
                   |-Werror=format-overflow=    |-Wformat-overflow after
                   |since                       |strlen in ILP32 since
                   |r12-5014-g6b8b959675a3e14c  |Ranger integration
             Blocks|                            |85741

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
There is a subtle difference between GCC 11 and GCC 12 in the range determined
for the length of the string argument to the %s directive that causes the
warning to trigger.  In GCC 11, EVRP reports it's [0, 2147483645] while in GCC
12 Ranger reports it's [0, 2147483644].  The difference of 1 between the upper
bounds is due to the improved range info (in both GCC 11 and 12 the strlen pass
sets the upper bound to 2147483644 but only in GCC 12 does Ranger report the
strlen result).

That being said, for the purposes of warning (but not optimization), when the
string length cannot be accurately determined, I think the sprintf pass should
use the size of the array the string is stored in.  So the warning in this case
should assume the result of strlen(p->id) is in [0, 7].  That would avoid it in
this instance and probably in quite a few others.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85741
[Bug 85741] [meta-bug] bogus/missing -Wformat-overflow

Reply via email to