Avoid calling Standard C string/array functions with NULL arguments
commit7fd9f61dbdbe4b0a05c7c66267f06119a16e869a
authorPhilip Withnall <withnall@endlessm.com>
Mon, 13 Aug 2018 13:13:28 +0000 (13 14:13 +0100)
committerPhilip Withnall <withnall@endlessm.com>
Mon, 13 Aug 2018 13:34:19 +0000 (13 14:34 +0100)
tree9074cd1ce451c085d1a90a93ff3c5ad76cb924cc
parent355228121e7656b1c48fd96fa4bcccc0d14161ae
Avoid calling Standard C string/array functions with NULL arguments

glibc string.h declares memcpy() with attribute(nonnull(1,2)), causing
calls with NULL arguments to be treated as undefined behaviour.
This is consistent with ISO C99 and C11, which state that passing 0
to string functions as an array length does not remove the requirement
that the pointer to the array is a valid pointer.
gcc -fsanitize=undefined catches this while running OSTree's test suite.

Similarly, running the GLib test suite reports similar issues for
qsort(), memmove(), memcmp().

(This is a partial cherry-pick of commit e5ed410c8c0fe823883 from GLib.)

Signed-off-by: Simon McVittie <smcv@debian.org>
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=775510
Reviewed-by: Colin Walters
gvdb-builder.c