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] Dynamic growable arrays for internal use


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


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