[PATCH] malloc: Improve checked_request2size
Cristian Rodríguez
cristian@rodriguez.im
Fri Jun 6 19:44:18 GMT 2025
On Fri, Jun 6, 2025 at 3:36 PM Paul Eggert <eggert@cs.ucla.edu> wrote:
>
> On 6/6/25 10:31, Wilco Dijkstra wrote:
> > - return 0;
> > + return (size_t)PTRDIFF_MAX + 1;
>
> Is there a reason this is (size_t)PTRDIFF_MAX + 1 rather than SIZE_MAX?
> If so, please comment why; if not, please change the expression to
> SIZE_MAX as that's likely to be a tad more efficient and won't leave the
> reader wondering why the code decreases the size request.
The compiler cannot do pointer arithmetic or have defined behaviour
with allocations larger than PTRDIFF_MAX.
PTRDIFF_MAX + 1 is a nice way to say "it cannot be handled" ..maybe
adding a constant explaining that fact is better.
More information about the Libc-alpha
mailing list