common/file.d fix malloc check (#14536)

This commit is contained in:
Walter Bright 2022-10-06 19:41:58 -07:00 committed by GitHub
parent e319e71628
commit e431c85202
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);
}
/**