aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO/InternalObject.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2024-07-16 15:38:35 +0200
committerJakub Konka <kubkon@jakubkonka.com>2024-07-18 09:13:09 +0200
commite9328e7da81300f1b3d3ebf0c91c6cc650e2747b (patch)
tree11d319db18a87a585744089df04f6214a048bd91 /src/link/MachO/InternalObject.zig
parent33388130775672df611091910e0cb1482a7eeb02 (diff)
downloadzig-e9328e7da81300f1b3d3ebf0c91c6cc650e2747b.tar.gz
zig-e9328e7da81300f1b3d3ebf0c91c6cc650e2747b.zip
macho: fix 32bit compilation issues
Diffstat (limited to 'src/link/MachO/InternalObject.zig')
-rw-r--r--src/link/MachO/InternalObject.zig10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/link/MachO/InternalObject.zig b/src/link/MachO/InternalObject.zig
index 55d7be00fb..ca6a53e983 100644
--- a/src/link/MachO/InternalObject.zig
+++ b/src/link/MachO/InternalObject.zig
@@ -415,8 +415,9 @@ pub fn resolveLiterals(self: *InternalObject, lp: *MachO.LiteralPool, macho_file
const rel = relocs[0];
assert(rel.tag == .@"extern");
const target = rel.getTargetSymbol(atom.*, macho_file).getAtom(macho_file).?;
- try buffer.ensureUnusedCapacity(target.size);
- buffer.resize(target.size) catch unreachable;
+ const target_size = std.math.cast(usize, target.size) orelse return error.Overflow;
+ try buffer.ensureUnusedCapacity(target_size);
+ buffer.resize(target_size) catch unreachable;
@memcpy(buffer.items, try self.getSectionData(target.n_sect));
const res = try lp.insert(gpa, header.type(), buffer.items);
buffer.clearRetainingCapacity();
@@ -572,8 +573,9 @@ pub fn writeAtoms(self: *InternalObject, macho_file: *MachO) !void {
if (!atom.flags.alive) continue;
const sect = atom.getInputSection(macho_file);
if (sect.isZerofill()) continue;
- const off = atom.value;
- const buffer = macho_file.sections.items(.out)[atom.out_n_sect].items[off..][0..atom.size];
+ const off = std.math.cast(usize, atom.value) orelse return error.Overflow;
+ const size = std.math.cast(usize, atom.size) orelse return error.Overflow;
+ const buffer = macho_file.sections.items(.out)[atom.out_n_sect].items[off..][0..size];
@memcpy(buffer, try self.getSectionData(atom.n_sect));
try atom.resolveRelocs(macho_file, buffer);
}