diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2023-10-31 04:26:57 -0400 |
|---|---|---|
| committer | Jacob Young <jacobly0@users.noreply.github.com> | 2023-10-31 21:37:35 -0400 |
| commit | d890e817610dd75feef55c1f7983190852c622a5 (patch) | |
| tree | 679d13309da35aa957a9d20d28671d9b8673b5a1 /lib/std/debug.zig | |
| parent | 50cdb65784937965b5871037ff40bc34d8eb14af (diff) | |
| download | zig-d890e817610dd75feef55c1f7983190852c622a5.tar.gz zig-d890e817610dd75feef55c1f7983190852c622a5.zip | |
mem: fix ub in writeInt
Use inline to vastly simplify the exposed API. This allows a
comptime-known endian parameter to be propogated, making extra functions
for a specific endianness completely unnecessary.
Diffstat (limited to 'lib/std/debug.zig')
| -rw-r--r-- | lib/std/debug.zig | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 5302105fe9..1bf1f7307c 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1135,8 +1135,8 @@ pub fn readElfDebugInfo( const gnu_debuglink = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size); const debug_filename = mem.sliceTo(@as([*:0]const u8, @ptrCast(gnu_debuglink.ptr)), 0); const crc_offset = mem.alignForward(usize, @intFromPtr(&debug_filename[debug_filename.len]) + 1, 4) - @intFromPtr(gnu_debuglink.ptr); - const crc_bytes = gnu_debuglink[crc_offset .. crc_offset + 4]; - separate_debug_crc = mem.readIntSliceNative(u32, crc_bytes); + const crc_bytes = gnu_debuglink[crc_offset..][0..4]; + separate_debug_crc = mem.readInt(u32, crc_bytes, native_endian); separate_debug_filename = debug_filename; continue; } @@ -1868,10 +1868,10 @@ pub const DebugInfo = struct { elf.PT_NOTE => { // Look for .note.gnu.build-id const note_bytes = @as([*]const u8, @ptrFromInt(info.dlpi_addr + phdr.p_vaddr))[0..phdr.p_memsz]; - const name_size = mem.readIntSliceNative(u32, note_bytes[0..4]); + const name_size = mem.readInt(u32, note_bytes[0..4], native_endian); if (name_size != 4) continue; - const desc_size = mem.readIntSliceNative(u32, note_bytes[4..8]); - const note_type = mem.readIntSliceNative(u32, note_bytes[8..12]); + const desc_size = mem.readInt(u32, note_bytes[4..8], native_endian); + const note_type = mem.readInt(u32, note_bytes[8..12], native_endian); if (note_type != elf.NT_GNU_BUILD_ID) continue; if (!mem.eql(u8, "GNU\x00", note_bytes[12..16])) continue; context.build_id = note_bytes[16..][0..desc_size]; |
