Skip to content

Commit 8541119

Browse files
committed
macho: handle empty string in ZigObject.getString
1 parent 96fa29b commit 8541119

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/link/MachO/Atom.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ extra: u32 = 0,
4242
pub fn getName(self: Atom, macho_file: *MachO) [:0]const u8 {
4343
return switch (self.getFile(macho_file)) {
4444
.dylib => unreachable,
45-
.zig_object => |x| x.strtab.buffer.items[self.name.pos..][0 .. self.name.len - 1 :0],
4645
inline else => |x| x.getString(self.name),
4746
};
4847
}

src/link/MachO/Symbol.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ pub fn weakRef(symbol: Symbol, macho_file: *MachO) bool {
5757

5858
pub fn getName(symbol: Symbol, macho_file: *MachO) [:0]const u8 {
5959
return switch (symbol.getFile(macho_file).?) {
60-
.zig_object => |x| x.strtab.buffer.items[symbol.name.pos..][0 .. symbol.name.len - 1 :0],
6160
inline else => |x| x.getString(symbol.name),
6261
};
6362
}

src/link/MachO/ZigObject.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,6 +1767,11 @@ fn addString(self: *ZigObject, allocator: Allocator, string: []const u8) !MachO.
17671767
return .{ .pos = off, .len = @intCast(string.len + 1) };
17681768
}
17691769

1770+
pub fn getString(self: ZigObject, string: MachO.String) [:0]const u8 {
1771+
if (string.len == 0) return "";
1772+
return self.strtab.buffer.items[string.pos..][0 .. string.len - 1 :0];
1773+
}
1774+
17701775
pub fn asFile(self: *ZigObject) File {
17711776
return .{ .zig_object = self };
17721777
}

0 commit comments

Comments
 (0)