[Bug c/83688] Please check if buffers may overlap when copying strings using sprintf
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Jan 4 21:52:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83688
--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
The warning does see that range (it's in the output of the -fdump-tree-vrp
option). The challenge with using ranges is to avoid false positives from
excessive bounds. For sizes, typically only the lower bound can be trusted.
The upper bound is very often meaningless. For instance, in something as
simple as the following, n's range is [0, UINT_MAX]:
void test (unsigned n)
{
memcpy (buf, buf + 5, n);
}
So all these warnings (-Warray-bounds, -Wformat-overflow, -Wrestrict,
-Wstringop-overflow, etc.) only use the more conservative of the two bounds,
usually the lower one.
More information about the Gcc-bugs
mailing list