public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/marxin/heads/D-fix-ubsan)] D: fix UBSAN
@ 2021-12-06 12:03 Martin Liska
0 siblings, 0 replies; only message in thread
From: Martin Liska @ 2021-12-06 12:03 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:c72e2c3a0a2dbfe3c1e4edbc9754f65bb4462bac
commit c72e2c3a0a2dbfe3c1e4edbc9754f65bb4462bac
Author: Martin Liska <mliska@suse.cz>
Date: Mon Dec 6 13:02:22 2021 +0100
D: fix UBSAN
Fixes:
gcc/d/expr.cc:2596:9: runtime error: null pointer passed as argument 2, which is declared to never be null
gcc/d/ChangeLog:
* expr.cc: Call memcpy only when length != 0.
Diff:
---
gcc/d/expr.cc | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 31680564bdd..22acbc07cde 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -2593,7 +2593,8 @@ public:
/* Copy the string contents to a null terminated string. */
dinteger_t length = (e->len * e->sz);
char *string = XALLOCAVEC (char, length + 1);
- memcpy (string, e->string, length);
+ if (length > 0)
+ memcpy (string, e->string, length);
string[length] = '\0';
/* String value and type includes the null terminator. */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-12-06 12:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-06 12:03 [gcc(refs/users/marxin/heads/D-fix-ubsan)] D: fix UBSAN Martin Liska
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).