From: Martin Liska Date: Mon, 6 Dec 2021 12:02:22 +0000 (+0100) Subject: D: fix UBSAN X-Git-Tag: basepoints/gcc-13~2459 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5791bf7a0a7705be6c3989c445e7c739220f3290;p=thirdparty%2Fgcc.git 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 --git a/gcc/d/expr.cc b/gcc/d/expr.cc index 2831eefc4ba6..8e1d43e2b8f8 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. */