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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #9 from Martin Sebor <msebor at gcc dot gnu.org> ---
I'm having trouble reproducing the warning due to the errors described in in
bug 80455.  But it's clear from the context of the warning that there is a path
to the memset call where the value of n is -1.  It's possible that the path is
not reachable and GCC doesn't see it.  The easiest thing to do then is to
assert that n cannot be negative.

In other similar reports, the warning would also disappear when the type of the
size argument changed to unsigned.  This is often because the signed size
argument starts out as unsigned (such as size_t) with some limited non-negative
range.  That range can be lost or turned into a positive-negative one in
unsigned to signed conversions.  When the positive-negative range becomes
subject to path splitting, it's not uncommon to see the negative (and
unreachable) path cause the warning.  Using an unsigned type for sizes helps
avoid this problem.

Reply via email to