| ... | ... | @@ -703,7 +703,8 @@ fn writeAtoms(macho_file: *MachO) !void { |
| 703 | 703 | log.debug(" (with padding {x})", .{padding_size}); |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | | const offset = this_sym.n_value - header.addr; |
| 706 | const offset = math.cast(usize, this_sym.n_value - header.addr) orelse |
| 707 | return error.Overflow; |
| 707 | 708 | log.debug(" (at offset 0x{x})", .{offset}); |
| 708 | 709 | |
| 709 | 710 | const code = Atom.getAtomCode(macho_file, atom_index); |
| ... | ... | @@ -749,7 +750,8 @@ fn writeThunks(macho_file: *MachO) !void { |
| 749 | 750 | |
| 750 | 751 | for (macho_file.thunks.items, 0..) |*thunk, i| { |
| 751 | 752 | if (thunk.getSize() == 0) continue; |
| 752 | | var buffer = try std.ArrayList(u8).initCapacity(gpa, thunk.getSize()); |
| 753 | const thunk_size = math.cast(usize, thunk.getSize()) orelse return error.Overflow; |
| 754 | var buffer = try std.ArrayList(u8).initCapacity(gpa, thunk_size); |
| 753 | 755 | defer buffer.deinit(); |
| 754 | 756 | try thunks.writeThunkCode(macho_file, thunk, buffer.writer()); |
| 755 | 757 | const thunk_atom = macho_file.getAtom(thunk.getStartAtomIndex()); |
| ... | ... | @@ -763,7 +765,8 @@ fn writeThunks(macho_file: *MachO) !void { |
| 763 | 765 | fn writePointerEntries(macho_file: *MachO, sect_id: u8, table: anytype) !void { |
| 764 | 766 | const gpa = macho_file.base.allocator; |
| 765 | 767 | const header = macho_file.sections.items(.header)[sect_id]; |
| 766 | | var buffer = try std.ArrayList(u8).initCapacity(gpa, header.size); |
| 768 | const capacity = math.cast(usize, header.size) orelse return error.Overflow; |
| 769 | var buffer = try std.ArrayList(u8).initCapacity(gpa, capacity); |
| 767 | 770 | defer buffer.deinit(); |
| 768 | 771 | for (table.entries.items) |entry| { |
| 769 | 772 | const sym = macho_file.getSymbol(entry); |
| ... | ... | @@ -779,7 +782,8 @@ fn writeStubs(macho_file: *MachO) !void { |
| 779 | 782 | const stubs_header = macho_file.sections.items(.header)[macho_file.stubs_section_index.?]; |
| 780 | 783 | const la_symbol_ptr_header = macho_file.sections.items(.header)[macho_file.la_symbol_ptr_section_index.?]; |
| 781 | 784 | |
| 782 | | var buffer = try std.ArrayList(u8).initCapacity(gpa, stubs_header.size); |
| 785 | const capacity = math.cast(usize, stubs_header.size) orelse return error.Overflow; |
| 786 | var buffer = try std.ArrayList(u8).initCapacity(gpa, capacity); |
| 783 | 787 | defer buffer.deinit(); |
| 784 | 788 | |
| 785 | 789 | for (0..macho_file.stub_table.count()) |index| { |
| ... | ... | @@ -799,7 +803,8 @@ fn writeStubHelpers(macho_file: *MachO) !void { |
| 799 | 803 | const cpu_arch = macho_file.base.options.target.cpu.arch; |
| 800 | 804 | const stub_helper_header = macho_file.sections.items(.header)[macho_file.stub_helper_section_index.?]; |
| 801 | 805 | |
| 802 | | var buffer = try std.ArrayList(u8).initCapacity(gpa, stub_helper_header.size); |
| 806 | const capacity = math.cast(usize, stub_helper_header.size) orelse return error.Overflow; |
| 807 | var buffer = try std.ArrayList(u8).initCapacity(gpa, capacity); |
| 803 | 808 | defer buffer.deinit(); |
| 804 | 809 | |
| 805 | 810 | { |
| ... | ... | @@ -842,7 +847,8 @@ fn writeLaSymbolPtrs(macho_file: *MachO) !void { |
| 842 | 847 | const la_symbol_ptr_header = macho_file.sections.items(.header)[macho_file.la_symbol_ptr_section_index.?]; |
| 843 | 848 | const stub_helper_header = macho_file.sections.items(.header)[macho_file.stub_helper_section_index.?]; |
| 844 | 849 | |
| 845 | | var buffer = try std.ArrayList(u8).initCapacity(gpa, la_symbol_ptr_header.size); |
| 850 | const capacity = math.cast(usize, la_symbol_ptr_header.size) orelse return error.Overflow; |
| 851 | var buffer = try std.ArrayList(u8).initCapacity(gpa, capacity); |
| 846 | 852 | defer buffer.deinit(); |
| 847 | 853 | |
| 848 | 854 | for (0..macho_file.stub_table.count()) |index| { |