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.
This commit is contained in:
parent
024842a38b
commit
934df19c52
1 changed files with 6 additions and 0 deletions
6
array.c
6
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue