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

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
I should also mention that the warning isn't without merit even if the path
where the index is strictly negative doesn't appear in the source code.  As far
as anyone can tell, the array index would be negative if SendDlgItemMessageW
returned a negative value.  It's not clear from the MSDN documentation whether
that can ever happen, but since the return type is signed GCC must assume it
can.  So at a minimum, the warning points out a potential bug.  If the function
can not, in fact, return a negative result, either it or its callers can
prevent the warning (and likely improve the quality of code emitted for its
callers) either by asserting that the value is not negative or by converting it
to an unsigned type (and asserting the result is in bounds of the array into
which it is used to index).

At the same time, the jump threading pass could determine that the path with
the negative index is undefined and avoid inserting it (or rather, replace it
with a trap).  That would prevent the warning as it's implemented today, though
it's not entirely clear that suppressing it would be helpful in the event that
the value did end up negative in the end.  Then the program would just abort. 
IIUC, Jeff's position on this is to both warn and trap.  The text of the
warning in that case might be more appropriately phrased as "subscript -1 may
be below array bounds" than "is below bounds."

Reply via email to