[v2] sprof: check pread size and offset for overflow
Paul Eggert
eggert@cs.ucla.edu
Fri Oct 17 19:49:55 GMT 2025
On 2025-10-17 11:39, DJ Delorie wrote:
> Checking for overflow and reporting an error is not as
> useful if your goal is to either (1) understand the code, or (2) fix the
> problem data.
Unfortunately we'll have to disagree. The first question I had when I
read the proposed code was "what about overflow?" and since the code on
some platforms relies on undefined behavior if signed overflow occurs,
the checks that I saw (which try to check for overflow but don't fully
succeed) were confusing and distracted me from the code's intended
purpose. In other words, to me the proposed code is not as clear as a
simple overflow check would be.
Moreover, one cannot rely on signed integer overflow wrapping around
reliably, as GCC does not guarantee this and in practice it sometimes
does not wrap around. So although signed overflow checks can make code
harder to understand (especially if you're not used to them), omitting
them here means the checking code is not fully checking.
More information about the Libc-alpha
mailing list