This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH v2 01/10] Do not pass NULL to memcpy
- From: Tom Tromey <tom at tromey dot com>
- To: gdb-patches at sourceware dot org
- Cc: Tom Tromey <tom at tromey dot com>
- Date: Mon, 1 Oct 2018 22:44:11 -0600
- Subject: [PATCH v2 01/10] Do not pass NULL to memcpy
- References: <20181002044420.17628-1-tom@tromey.com>
-fsanitize=undefined pointed out a spot that passes NULL to memcpy,
which is undefined behavior according to the C standard.
gdb/ChangeLog
2018-10-01 Tom Tromey <tom@tromey.com>
* namespace.c (add_using_directive): Don't pass NULL to memcpy.
---
gdb/ChangeLog | 4 ++++
gdb/namespace.c | 5 +++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/gdb/namespace.c b/gdb/namespace.c
index be998d9d49..85c0c4b14d 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;
--
2.17.1