[Bug c/89699] [8/9 Regression] false warning -Wstringop-overflow and memcmp

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Mar 13 13:55:00 GMT 2019


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2019-03-13
                 CC|                            |jakub at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Warning like this shouldn't be enabled by default with the amount of false
positives it has.

In this case, we have:
  # RANGE [-2147483648, 0]
  min_6 = MIN_EXPR <len1_5, 0>;
  # RANGE ~[1, 18446744071562067967]
  _3 = (long unsigned int) min_6;
  _7 = __builtin_memcmp (s1.0_1, "", _3);
where we don't know anything about len1 (VARYING), but as we folded strlen ("")
into 0, it is min is actually MIN (len1, 0) and so the range of it is indeed
[-2147483648, 0] and that converted to size_t is 0 or -2147483648UL or higher.

As a workaround, I'd strongly recommend not using int variables to hold sizes
of strings, it should be using size_t instead.


More information about the Gcc-bugs mailing list