From 958369aaef8771932c3bc70b6ce21150941cd9e0 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Tue, 19 May 2020 17:40:40 -0700 Subject: [PATCH] Don't fail do to implementation-specific malloc behavior The documentation for malloc states that an attempt to allocate memory of size 0 results in implementation-specific behavior. Some implementations return `NULL`, and others return a pointer that is expected to be `free`'d. Signed-off-by: Scott K Logan --- src/string_array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/string_array.c b/src/string_array.c index 42e99eec..dffbb648 100644 --- a/src/string_array.c +++ b/src/string_array.c @@ -52,7 +52,7 @@ rcutils_string_array_init( } string_array->size = size; string_array->data = allocator->zero_allocate(size, sizeof(char *), allocator->state); - if (NULL == string_array->data) { + if (NULL == string_array->data && 0 != size) { RCUTILS_SET_ERROR_MSG("failed to allocator string array"); return RCUTILS_RET_BAD_ALLOC; }