aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2022-11-02 17:03:20 +0100
committerGitHub <noreply@github.com>2022-11-02 17:03:20 +0100
commit7ec6fd30f0a8839834da35172c519ae63689aa7d (patch)
tree969a026aa9e357be47fb4dc8f6e16acc34ba4fc4
parent9e1576418fa3d619bf27af89db77060f68c1b211 (diff)
parent0ca773114a2959176da06905857cdfc1e1a5327d (diff)
Merge pull request #2171 from Kelimion/os_read_windows
Fix os.read implementation on Windows.
-rw-r--r--core/os/file_windows.odin6
1 files changed, 4 insertions, 2 deletions
diff --git a/core/os/file_windows.odin b/core/os/file_windows.odin
index 8019b0440..91d206d2e 100644
--- a/core/os/file_windows.odin
+++ b/core/os/file_windows.odin
@@ -162,7 +162,8 @@ read :: proc(fd: Handle, data: []byte) -> (int, Errno) {
total_read: int
length := len(data)
- to_read := min(win32.DWORD(length), MAX_RW)
+ // NOTE(Jeroen): `length` can't be casted to win32.DWORD here because it'll overflow if > 4 GiB and return 0 if exactly that.
+ to_read := min(i64(length), MAX_RW)
e: win32.BOOL
if is_console {
@@ -172,7 +173,8 @@ read :: proc(fd: Handle, data: []byte) -> (int, Errno) {
return int(total_read), err
}
} else {
- e = win32.ReadFile(handle, &data[total_read], to_read, &single_read_length, nil)
+ // NOTE(Jeroen): So we cast it here *after* we've ensured that `to_read` is at most MAX_RW (1 GiB)
+ e = win32.ReadFile(handle, &data[total_read], win32.DWORD(to_read), &single_read_length, nil)
}
if single_read_length <= 0 || !e {
err := Errno(win32.GetLastError())