From 3c8e1bc25b6d122ce1295e2e33bb9f54ae801ec0 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Fri, 4 Sep 2020 12:48:36 +0200 Subject: [PATCH] std: Fix for 32bit systems --- lib/std/fs.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 4005f90fcb..a217fb3e9b 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -1457,7 +1457,10 @@ pub const Dir = struct { var file = try self.openFile(file_path, .{}); defer file.close(); - const stat_size = size_hint orelse try file.getEndPos(); + // If the file size doesn't fit a usize it'll be certainly greater than + // `max_bytes` + const stat_size = size_hint orelse math.cast(usize, try file.getEndPos()) catch + return error.FileTooBig; return file.readToEndAllocOptions(allocator, max_bytes, stat_size, alignment, optional_sentinel); }