Re: [PATCH] avoid pointer arithmetic involving NULL in FLEX_ALLOC_MEM

2016-10-16 Thread Jeff King
On Sun, Oct 16, 2016 at 12:06:02PM +0200, René Scharfe wrote: > > Yeah, this NULL computation is pretty nasty. I recall trying to get rid > > of it, but I think it is impossible to do so portably while still using > > the generic xalloc_flex() helper. > > The only way I see is to pass the type

Re: [PATCH] avoid pointer arithmetic involving NULL in FLEX_ALLOC_MEM

2016-10-16 Thread René Scharfe
Am 15.10.2016 um 19:13 schrieb Jeff King: > On Sat, Oct 15, 2016 at 06:23:11PM +0200, René Scharfe wrote: > >> Calculating offsets involving a NULL pointer is undefined. It works in >> practice (for now?), but we should not rely on it. Allocate first and >> then simply refer to the flexible

Re: [PATCH] avoid pointer arithmetic involving NULL in FLEX_ALLOC_MEM

2016-10-15 Thread Jeff King
On Sat, Oct 15, 2016 at 06:23:11PM +0200, René Scharfe wrote: > Calculating offsets involving a NULL pointer is undefined. It works in > practice (for now?), but we should not rely on it. Allocate first and > then simply refer to the flexible array member by its name instead of > performing

[PATCH] avoid pointer arithmetic involving NULL in FLEX_ALLOC_MEM

2016-10-15 Thread René Scharfe
Calculating offsets involving a NULL pointer is undefined. It works in practice (for now?), but we should not rely on it. Allocate first and then simply refer to the flexible array member by its name instead of performing pointer arithmetic up front. The resulting code is slightly shorter,