From e431c85202fcea8192193c77c86e1872b8ae2b59 Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Thu, 6 Oct 2022 19:41:58 -0700 Subject: [PATCH] common/file.d fix malloc check (#14536) --- compiler/src/dmd/common/file.d | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/compiler/src/dmd/common/file.d b/compiler/src/dmd/common/file.d index 8f34b5319a..89e702703e 100644 --- a/compiler/src/dmd/common/file.d +++ b/compiler/src/dmd/common/file.d @@ -144,9 +144,14 @@ struct FileMapping(Datum) import core.stdc.string : strlen; import core.stdc.stdlib : malloc; import core.stdc.string : memcpy; - auto totalNameLength = filename.strlen() + 1; - name = cast(char*) memcpy(malloc(totalNameLength), filename, totalNameLength); - name || assert(0, "FileMapping: Out of memory."); + const totalNameLength = filename.strlen() + 1; + auto namex = cast(char*) malloc(totalNameLength); + if (!namex) + { + fprintf(stderr, "FileMapping: Out of memory."); + exit(1); + } + name = cast(char*) memcpy(namex, filename, totalNameLength); } /**