summaryrefslogtreecommitdiff
path: root/gdb/namespace.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-07-26 17:48:40 -0600
committerTom Tromey <tom@tromey.com>2018-10-03 15:19:06 -0600
commit10657c047e4e0257440c80fda5f4e23a3452616c (patch)
tree68d91988f0db35427f735036697378d5793e689f /gdb/namespace.c
parentfb9bbfd7f2d39a1d4850fcf0f63ef1f077f55e4b (diff)
downloadbinutils-gdb-10657c047e4e0257440c80fda5f4e23a3452616c.tar.gz
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.
Diffstat (limited to 'gdb/namespace.c')
-rw-r--r--gdb/namespace.c5
1 files changed, 3 insertions, 2 deletions
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;