]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
array: always return non-NULL pointer from ARR_GetElements()
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 1 Dec 2015 13:24:36 +0000 (14:24 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 2 Dec 2015 11:04:09 +0000 (12:04 +0100)
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.

array.c

diff --git a/array.c b/array.c
index 26a3160de0bf25beda54f292fd58a659cea77d19..ffe5a4eb7fbb3e12b9e09566edff7c4b178e46e4 100644 (file)
--- 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;
 }