This is the mail archive of the
mailing list for the GCC project.
RFA: libiberty: avoid UBSAN complaint in cplus-dem.c
- From: Tom Tromey <tom at tromey dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 27 Jul 2018 11:12:33 -0600
- Subject: RFA: libiberty: avoid UBSAN complaint in cplus-dem.c
I built gdb with -fsanitize=undefined, and there was a complaint coming
from cplus-dem.c. remember_Btype can call memcpy with a NULL pointer,
which is undefined behavior according to the C standard.
This patch fixes the problem for me. I tested this by rebuilding gdb
(with -fsanitize=undefined) and re-running the test suite.
2018-07-27 Tom Tromey <firstname.lastname@example.org>
* cplus-dem.c (remember_Btype): Don't call memcpy with LEN==0.
diff --git a/libiberty/cplus-dem.c b/libiberty/cplus-dem.c
index 6d58bd899bf..4f29d54d089 100644
@@ -4471,7 +4471,8 @@ remember_Btype (struct work_stuff *work, const char *start,
tem = XNEWVEC (char, len + 1);
- memcpy (tem, start, len);
+ if (len > 0)
+ memcpy (tem, start, len);
tem[len] = '\0';
work -> btypevec[index] = tem;