aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-11-21 19:39:32 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-11-21 19:43:08 -0700
commit6afcaf4a08b6fb1cce0cdb2393fc1d4cd041509c (patch)
treebf4a17c51d53b720077e8315c5d0a38f20eba219 /src/Module.zig
parent96e5f661bd34d98bba89bcb70c9db059aaf38641 (diff)
downloadzig-6afcaf4a08b6fb1cce0cdb2393fc1d4cd041509c.tar.gz
zig-6afcaf4a08b6fb1cce0cdb2393fc1d4cd041509c.zip
stage2: fix the build for 32-bit architectures
* Introduce a mechanism into Sema for emitting a compile error when an integer is too big and we need it to fit into a usize. * Add `@intCast` where necessary * link/MachO: fix an unnecessary allocation when all that was happening was appending zeroes to an ArrayList. * Add `error.Overflow` as a possible error to some codepaths, allowing usage of `math.intCast`. closes #9710
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/Module.zig b/src/Module.zig
index cc5209a217..33b3c43423 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -3661,7 +3661,8 @@ pub fn embedFile(mod: *Module, cur_file: *File, rel_file_path: []const u8) !*Emb
defer file.close();
const stat = try file.stat();
- const bytes = try file.readToEndAllocOptions(gpa, std.math.maxInt(u32), stat.size, 1, 0);
+ const size_usize = try std.math.cast(usize, stat.size);
+ const bytes = try file.readToEndAllocOptions(gpa, std.math.maxInt(u32), size_usize, 1, 0);
log.debug("new embedFile. resolved_root_path={s}, resolved_path={s}, sub_file_path={s}, rel_file_path={s}", .{
resolved_root_path, resolved_path, sub_file_path, rel_file_path,
@@ -3694,7 +3695,8 @@ pub fn detectEmbedFileUpdate(mod: *Module, embed_file: *EmbedFile) !void {
if (unchanged_metadata) return;
const gpa = mod.gpa;
- const bytes = try file.readToEndAllocOptions(gpa, std.math.maxInt(u32), stat.size, 1, 0);
+ const size_usize = try std.math.cast(usize, stat.size);
+ const bytes = try file.readToEndAllocOptions(gpa, std.math.maxInt(u32), size_usize, 1, 0);
gpa.free(embed_file.bytes);
embed_file.bytes = bytes;
embed_file.stat_size = stat.size;