[PATCH 2/2] malloc: make malloc fail with requests larger than PTRDIFF_MAX
Paul Eggert
eggert@cs.ucla.edu
Thu Dec 27 16:59:00 GMT 2018
Adhemerval Zanella wrote:
> I added for consistency so all internal allocation, after alignment and padding
> adjustment, will be also limited by PTRDIFF_MAX.
It's not a big deal, but as I see it the tradeoff here is:
* Limiting the size to (PTRDIFF_MAX - padsize) means that internal allocators
are free to use ptrdiff_t in size calculation, e.g., when subtracting pointers.
Currently I don't think they don't do that but maybe I'm wrong, or maybe they
will do that someday, so it's safer to impose the stricter limit
* Merely limiting the size to PTRDIFF_MAX is easier to explain to users, and is
a tiny bit faster because at the machine level it's faster to compare to
0x7fff..ffff than it is to compare to 0x7fff...fff1 (or whatever) because you
can just look at the sign bit.
I could see it going either way.
More information about the Libc-alpha
mailing list