From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id AAEEA3858C27; Thu, 9 Dec 2021 08:46:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AAEEA3858C27 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Martin Liska To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-5854] D: fix UBSAN X-Act-Checkin: gcc X-Git-Author: Martin Liska X-Git-Refname: refs/heads/master X-Git-Oldrev: af93386ffc18ca6c7d1949751ff97cc6ce092b2c X-Git-Newrev: 5791bf7a0a7705be6c3989c445e7c739220f3290 Message-Id: <20211209084638.AAEEA3858C27@sourceware.org> Date: Thu, 9 Dec 2021 08:46:38 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Dec 2021 08:46:38 -0000 https://gcc.gnu.org/g:5791bf7a0a7705be6c3989c445e7c739220f3290 commit r12-5854-g5791bf7a0a7705be6c3989c445e7c739220f3290 Author: Martin Liska 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 2831eefc4ba..8e1d43e2b8f 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. */