From: Tom Tromey Date: Thu, 26 Jul 2018 23:48:40 +0000 (-0600) Subject: Do not pass NULL to memcpy X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=10657c047e4e0257440c80fda5f4e23a3452616c;p=binutils-gdb.git Do not pass NULL to memcpy -fsanitize=undefined pointed out a spot that passes NULL to memcpy, which is undefined behavior according to the C standard. gdb/ChangeLog 2018-10-03 Tom Tromey * namespace.c (add_using_directive): Don't pass NULL to memcpy. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f5448c31d80..1f8b8e57225 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2018-10-03 Tom Tromey + + * namespace.c (add_using_directive): Don't pass NULL to memcpy. + 2018-10-03 Philippe Waroquiers * tid-parse.c (tid_is_in_list): Fix wrong 'See' comment. diff --git a/gdb/namespace.c b/gdb/namespace.c index be998d9d491..85c0c4b14d7 100644 --- a/gdb/namespace.c +++ b/gdb/namespace.c @@ -111,8 +111,9 @@ add_using_directive (struct using_direct **using_directives, else newobj->declaration = declaration; - memcpy (newobj->excludes, excludes.data (), - excludes.size () * sizeof (*newobj->excludes)); + if (!excludes.empty ()) + memcpy (newobj->excludes, excludes.data (), + excludes.size () * sizeof (*newobj->excludes)); newobj->excludes[excludes.size ()] = NULL; newobj->next = *using_directives;