From: Miroslav Lichvar Date: Tue, 1 Dec 2015 13:24:36 +0000 (+0100) Subject: array: always return non-NULL pointer from ARR_GetElements() X-Git-Tag: 2.3-pre1~82 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=934df19c52981628f8d154a1fee4c2dbee31c61f;p=thirdparty%2Fchrony.git array: always return non-NULL pointer from ARR_GetElements() Some libc calls like memcpy() expect the pointer to be valid even when the size is zero and there is nothing to do. Instead of checking the size before all such calls, modify ARR_GetElements() to return a pointer to the array instance itself if data was not allocated yet. --- diff --git a/array.c b/array.c index 26a3160d..ffe5a4eb 100644 --- a/array.c +++ b/array.c @@ -103,6 +103,12 @@ ARR_GetElement(ARR_Instance array, unsigned int index) void * ARR_GetElements(ARR_Instance array) { + /* Return a non-NULL pointer when the array has zero size */ + if (!array->data) { + assert(!array->used); + return array; + } + return array->data; }