authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-22 13:35:55+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-22 13:35:55+02:00
log8541119e9b57b274fa01f1dae101adca5ac2245f
tree1c9ea570f8d314be721529f11f2c8b3094ba9a0b
parent96fa29b90f16ea12a4fea944636f5c5de73160fc

macho: handle empty string in ZigObject.getString


3 files changed, 5 insertions(+), 2 deletions(-)

src/link/MachO/Atom.zig-1
...@@ -42,7 +42,6 @@ extra: u32 = 0,...@@ -42,7 +42,6 @@ extra: u32 = 0,
42pub fn getName(self: Atom, macho_file: *MachO) [:0]const u8 {42pub fn getName(self: Atom, macho_file: *MachO) [:0]const u8 {
43 return switch (self.getFile(macho_file)) {43 return switch (self.getFile(macho_file)) {
44 .dylib => unreachable,44 .dylib => unreachable,
45 .zig_object => |x| x.strtab.buffer.items[self.name.pos..][0 .. self.name.len - 1 :0],
46 inline else => |x| x.getString(self.name),45 inline else => |x| x.getString(self.name),
47 };46 };
48}47}
src/link/MachO/Symbol.zig-1
...@@ -57,7 +57,6 @@ pub fn weakRef(symbol: Symbol, macho_file: *MachO) bool {...@@ -57,7 +57,6 @@ pub fn weakRef(symbol: Symbol, macho_file: *MachO) bool {
5757
58pub fn getName(symbol: Symbol, macho_file: *MachO) [:0]const u8 {58pub fn getName(symbol: Symbol, macho_file: *MachO) [:0]const u8 {
59 return switch (symbol.getFile(macho_file).?) {59 return switch (symbol.getFile(macho_file).?) {
60 .zig_object => |x| x.strtab.buffer.items[symbol.name.pos..][0 .. symbol.name.len - 1 :0],
61 inline else => |x| x.getString(symbol.name),60 inline else => |x| x.getString(symbol.name),
62 };61 };
63}62}
src/link/MachO/ZigObject.zig+5
...@@ -1767,6 +1767,11 @@ fn addString(self: *ZigObject, allocator: Allocator, string: []const u8) !MachO....@@ -1767,6 +1767,11 @@ fn addString(self: *ZigObject, allocator: Allocator, string: []const u8) !MachO.
1767 return .{ .pos = off, .len = @intCast(string.len + 1) };1767 return .{ .pos = off, .len = @intCast(string.len + 1) };
1768}1768}
17691769
1770pub 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
1770pub fn asFile(self: *ZigObject) File {1775pub fn asFile(self: *ZigObject) File {
1771 return .{ .zig_object = self };1776 return .{ .zig_object = self };
1772}1777}