avoid pointer arithmetic involving NULL in FLEX_ALLOC_MEM
commite9451782cfbe9fc9105bf63228bca3e2265af8f8
authorRené Scharfe <l.s.r@web.de>
Sat, 15 Oct 2016 16:23:11 +0000 (15 18:23 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 17 Oct 2016 21:42:31 +0000 (17 14:42 -0700)
tree273fb9ec943e2d478f61011b8a92c93d01d3b504
parentddd0bfac7cfaabc7c0422ecee9604ede9c4841d1
avoid pointer arithmetic involving NULL in FLEX_ALLOC_MEM

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, easier to read and doesn't rely on undefined behaviour.

NB: The cast to a (non-const) void pointer is necessary to keep support
for flexible array members declared as const.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-compat-util.h