From f3be11dc2930cd6f500ec816f426de9b98c84eec Mon Sep 17 00:00:00 2001 From: vladchicos Date: Sun, 1 Aug 2021 14:59:39 +0300 Subject: [PATCH 1/2] Fix Issue 16218 - Windows std.file.readImpl should be marked @system. --- std/file.d | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/std/file.d b/std/file.d index 6bcb231d7..f7407ce4a 100644 --- a/std/file.d +++ b/std/file.d @@ -402,24 +402,24 @@ version (Posix) private void[] readImpl(scope const(char)[] name, scope const(FS version (Windows) private void[] readImpl(scope const(char)[] name, scope const(FSChar)* namez, - size_t upTo = size_t.max) @safe + size_t upTo = size_t.max) @system { import core.memory : GC; import std.algorithm.comparison : min; static trustedCreateFileW(scope const(wchar)* namez, DWORD dwDesiredAccess, DWORD dwShareMode, SECURITY_ATTRIBUTES *lpSecurityAttributes, DWORD dwCreationDisposition, - DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) @trusted + DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) { return CreateFileW(namez, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); } - static trustedCloseHandle(HANDLE hObject) @trusted + static trustedCloseHandle(HANDLE hObject) { return CloseHandle(hObject); } - static trustedGetFileSize(HANDLE hFile, out ulong fileSize) @trusted + static trustedGetFileSize(HANDLE hFile, out ulong fileSize) { DWORD sizeHigh; DWORD sizeLow = GetFileSize(hFile, &sizeHigh); @@ -428,7 +428,7 @@ version (Windows) private void[] readImpl(scope const(char)[] name, scope const( fileSize = makeUlong(sizeLow, sizeHigh); return result; } - static trustedReadFile(HANDLE hFile, void *lpBuffer, ulong nNumberOfBytesToRead) @trusted + static trustedReadFile(HANDLE hFile, void *lpBuffer, ulong nNumberOfBytesToRead) { // Read by chunks of size < 4GB (Windows API limit) ulong totalNumRead = 0; @@ -456,11 +456,11 @@ version (Windows) private void[] readImpl(scope const(char)[] name, scope const( ulong fileSize = void; cenforce(trustedGetFileSize(h, fileSize), name, namez); size_t size = min(upTo, fileSize); - auto buf = () @trusted { return GC.malloc(size, GC.BlkAttr.NO_SCAN)[0 .. size]; } (); + auto buf = () { return GC.malloc(size, GC.BlkAttr.NO_SCAN)[0 .. size]; } (); scope(failure) { - () @trusted { GC.free(buf.ptr); } (); + () { GC.free(buf.ptr); } (); } if (size) From 95329239c93c4574919a04146578265cbbd5cba4 Mon Sep 17 00:00:00 2001 From: vladchicos Date: Mon, 2 Aug 2021 17:55:56 +0300 Subject: [PATCH 2/2] Windows readImpl is now marked @trusted --- std/file.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/std/file.d b/std/file.d index f7407ce4a..741656d74 100644 --- a/std/file.d +++ b/std/file.d @@ -402,7 +402,7 @@ version (Posix) private void[] readImpl(scope const(char)[] name, scope const(FS version (Windows) private void[] readImpl(scope const(char)[] name, scope const(FSChar)* namez, - size_t upTo = size_t.max) @system + size_t upTo = size_t.max) @trusted { import core.memory : GC; import std.algorithm.comparison : min;