diff options
author | Martin Liska <mliska@suse.cz> | 2021-12-06 13:02:22 +0100 |
---|---|---|
committer | Martin Liska <mliska@suse.cz> | 2021-12-09 09:46:25 +0100 |
commit | 5791bf7a0a7705be6c3989c445e7c739220f3290 (patch) | |
tree | 0740c189cad37c164a6d2e9ba643bf927578bd98 /gcc | |
parent | af93386ffc18ca6c7d1949751ff97cc6ce092b2c (diff) | |
download | gcc-5791bf7a0a7705be6c3989c445e7c739220f3290.zip gcc-5791bf7a0a7705be6c3989c445e7c739220f3290.tar.gz gcc-5791bf7a0a7705be6c3989c445e7c739220f3290.tar.bz2 |
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/d/expr.cc | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc index 2831eef..8e1d43e 100644 --- a/gcc/d/expr.cc +++ b/gcc/d/expr.cc @@ -2598,7 +2598,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. */ |