* RFA: libiberty: avoid UBSAN complaint in cplus-dem.c
@ 2018-07-27 17:12 Tom Tromey
2018-07-27 20:18 ` Ian Lance Taylor via gcc-patches
0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2018-07-27 17:12 UTC (permalink / raw)
To: gcc-patches
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.
Ok?
Tom
2018-07-27 Tom Tromey <tom@tromey.com>
* 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
--- a/libiberty/cplus-dem.c
+++ b/libiberty/cplus-dem.c
@@ -4471,7 +4471,8 @@ remember_Btype (struct work_stuff *work, const char *start,
char *tem;
tem = XNEWVEC (char, len + 1);
- memcpy (tem, start, len);
+ if (len > 0)
+ memcpy (tem, start, len);
tem[len] = '\0';
work -> btypevec[index] = tem;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: RFA: libiberty: avoid UBSAN complaint in cplus-dem.c
2018-07-27 17:12 RFA: libiberty: avoid UBSAN complaint in cplus-dem.c Tom Tromey
@ 2018-07-27 20:18 ` Ian Lance Taylor via gcc-patches
0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor via gcc-patches @ 2018-07-27 20:18 UTC (permalink / raw)
To: Tom Tromey; +Cc: gcc-patches
On Fri, Jul 27, 2018 at 10:12 AM, Tom Tromey <tom@tromey.com> wrote:
> 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.
>
> Ok?
>
> Tom
>
> 2018-07-27 Tom Tromey <tom@tromey.com>
>
> * cplus-dem.c (remember_Btype): Don't call memcpy with LEN==0.
This is OK.
Thanks.
Ian
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-07-27 20:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-27 17:12 RFA: libiberty: avoid UBSAN complaint in cplus-dem.c Tom Tromey
2018-07-27 20:18 ` Ian Lance Taylor via gcc-patches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).