Skip to content

Commit

Permalink
Don't fail do to implementation-specific malloc behavior
Browse files Browse the repository at this point in the history
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 <logans@cottsay.net>
  • Loading branch information
cottsay committed May 20, 2020
1 parent 3d38d49 commit 958369a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/string_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 958369a

Please sign in to comment.