mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-14 19:55:12 +01:00
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
This commit is contained in:
parent
355228121e
commit
7fd9f61dbd
@ -293,7 +293,8 @@ file_builder_add_string (FileBuilder *fb,
|
||||
chunk->offset = fb->offset;
|
||||
chunk->size = length;
|
||||
chunk->data = g_malloc (length);
|
||||
memcpy (chunk->data, string, length);
|
||||
if (length != 0)
|
||||
memcpy (chunk->data, string, length);
|
||||
|
||||
*start = guint32_to_le (fb->offset);
|
||||
*size = guint16_to_le (length);
|
||||
|
Loading…
x
Reference in New Issue
Block a user