https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100477
andysem at mail dot ru changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |---
--- Comment #2 from andysem at mail dot ru ---
(In reply to Martin Sebor from comment #1)
>
> Since n is set to _size + 4 in test(), (n < _size) holds only if the
> addition wraps around zero, implying _size is excessively large.
If `_size + 4` does overflow, the result of memset is still valid (i.e. it is
filling what it is supposed to fill), and the warning is incorrect.
> The
> warning can be avoided by asserting that that isn't so, e.g., by adding the
> following
>
> if (_size >= __PTRDIFF_MAX__ / 4)
> __builtin_unreachable ();
>
> just before the memset call.
I don't think users should be required to insert non-portable asserts like
these to be able to use memset without warnings.
Besides, this assert is incorrect as it will prevent memset to be called if
(_size >= __PTRDIFF_MAX__ / 4). (Why `/ 4`, BTW?)
I'm reopening because I think, as it currently works, the warning is bogus and
should be fixed. It is not actionable on the user's side and the suggested
workaround is not practical.