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  <tom@tromey.com>

	* namespace.c (add_using_directive): Don't pass NULL to memcpy.
This commit is contained in:
Tom Tromey
2018-07-26 17:48:40 -06:00
parent fb9bbfd7f2
commit 10657c047e
2 changed files with 7 additions and 2 deletions

View File

@ -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;