diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2022-11-08 15:45:15 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2022-11-08 15:45:15 +0100 |
| commit | 7145064efde75aaf4711671d1f5461ea56040815 (patch) | |
| tree | 5fe09e7cd38f60ebc7d200468077b518d5be89b9 /src | |
| parent | 7d48cb11389f5dfe73d25e59c1038398a8ba9ca9 (diff) | |
| download | zig-7145064efde75aaf4711671d1f5461ea56040815.tar.gz zig-7145064efde75aaf4711671d1f5461ea56040815.zip | |
macho: fix parsing len of DW_FORM_string
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/MachO/DwarfInfo.zig | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/link/MachO/DwarfInfo.zig b/src/link/MachO/DwarfInfo.zig index 48c5782571..dad248f60e 100644 --- a/src/link/MachO/DwarfInfo.zig +++ b/src/link/MachO/DwarfInfo.zig @@ -257,13 +257,21 @@ pub const Attribute = struct { } pub fn getString(self: Attribute, ctx: DwarfInfo, cuh: CompileUnit.Header) ?[]const u8 { - if (self.form != dwarf.FORM.strp) return null; const debug_info = self.getDebugInfo(ctx); - const off = if (cuh.is_64bit) - mem.readIntLittle(u64, debug_info[0..8]) - else - mem.readIntLittle(u32, debug_info[0..4]); - return ctx.getString(off); + + switch (self.form) { + dwarf.FORM.string => { + return mem.sliceTo(@ptrCast([*:0]const u8, debug_info.ptr), 0); + }, + dwarf.FORM.strp => { + const off = if (cuh.is_64bit) + mem.readIntLittle(u64, debug_info[0..8]) + else + mem.readIntLittle(u32, debug_info[0..4]); + return ctx.getString(off); + }, + else => return null, + } } pub fn getConstant(self: Attribute, ctx: DwarfInfo) !?i128 { @@ -440,8 +448,9 @@ fn findFormSize(self: DwarfInfo, form: u64, di_off: usize, cuh: CompileUnit.Head dwarf.FORM.string => { var count: usize = 0; - while (true) : (count += 1) { + while (true) { const byte = try reader.readByte(); + count += 1; if (byte == 0x0) break; } return count; |
