This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 2/2] malloc: make malloc fail with requests larger than PTRDIFF_MAX



On 27/12/2018 14:25, Paul Eggert wrote:
> 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.

As Wilco has pointed out, internally sysmalloc will align up PTRDIFF_MAX - C
for C < pagesize() to PTRDIFF_MAX + 1. One option is to move the check size
on sysmalloc instead (before mmap/sbrk or morecore calls).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]