Avoid calling Standard C string/array functions with NULL arguments
commite5ed410c8c0fe823883b65b293fb2d9c9d12673a
authorSimon McVittie <smcv@debian.org>
Fri, 2 Dec 2016 10:03:16 +0000 (2 10:03 +0000)
committerSimon McVittie <smcv@debian.org>
Fri, 2 Dec 2016 19:10:39 +0000 (2 19:10 +0000)
treef42abcea13b43f45e4393eea7d458fbc16431d1f
parent5e7eaaaaeead0925a9267515ad583357f44274b0
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().

Signed-off-by: Simon McVittie <smcv@debian.org>
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=775510
Reviewed-by: Colin Walters
gio/gconverterinputstream.c
gio/gconverteroutputstream.c
gio/gdesktopappinfo.c
gio/gunixsocketaddress.c
gio/gvdb/gvdb-builder.c
glib/garray.c
glib/goption.c
glib/gstrfuncs.c
glib/gtestutils.h
gobject/gtype.c