mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
macho: fix invalid ZigObject size calculation
This commit is contained in:
parent
35ac066f1d
commit
82144a9073
@ -285,15 +285,9 @@ pub fn checkDuplicates(self: *ZigObject, dupes: anytype, macho_file: *MachO) !vo
|
||||
/// This is just a temporary helper function that allows us to re-read what we wrote to file into a buffer.
|
||||
/// We need this so that we can write to an archive.
|
||||
/// TODO implement writing ZigObject data directly to a buffer instead.
|
||||
pub fn readFileContents(self: *ZigObject, macho_file: *MachO) !void {
|
||||
pub fn readFileContents(self: *ZigObject, size: usize, macho_file: *MachO) !void {
|
||||
const gpa = macho_file.base.comp.gpa;
|
||||
var end_pos: u64 = 0;
|
||||
for (macho_file.segments.items) |seg| {
|
||||
end_pos = @max(end_pos, seg.fileoff + seg.filesize);
|
||||
}
|
||||
const size = std.math.cast(usize, end_pos) orelse return error.Overflow;
|
||||
try self.data.resize(gpa, size);
|
||||
|
||||
const amt = try macho_file.base.file.?.preadAll(self.data.items, 0);
|
||||
if (amt != size) return error.InputOutput;
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ pub fn flushStaticLib(macho_file: *MachO, comp: *Compilation, module_obj_path: ?
|
||||
|
||||
// TODO we can avoid reading in the file contents we just wrote if we give the linker
|
||||
// ability to write directly to a buffer.
|
||||
try zo.readFileContents(macho_file);
|
||||
try zo.readFileContents(off, macho_file);
|
||||
}
|
||||
|
||||
var files = std.ArrayList(File.Index).init(gpa);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user