[PATCH] Dynamic growable arrays for internal use

Florian Weimer fweimer@redhat.com
Fri May 5 15:23:00 GMT 2017


On 05/05/2017 05:13 PM, Paul Eggert wrote:
> Florian Weimer wrote:
>> Does anyone have comments about the interface and implementation?
> 
> It suffers from a common problem: it can allocate objects containing 
> more than PTRDIFF_MAX bytes. Such objects do not work in C, because 
> pointer subtraction has undefined behavior

Isn't this a non-sequitur?  You can surely allocate such objects (on 
some architectures, not all of course).  You just have to be careful 
with pointer differences.  In particular, for an expression P[N] with P 
a pointer type and N an integer type, N is *not* converted to ptrdiff_t.

I don't think the current implementation computes any pointer 
differences, so it avoids this issue.  Element counts are kept in size_t 
variables.

Thanks,
Florian



More information about the Libc-alpha mailing list