debug: Fix end-of-stream condition in DWARF parser

This commit is contained in:
LemonBoy 2020-02-26 21:41:29 +01:00 committed by Andrew Kelley
parent fd1eade4ca
commit 6a0927d8c1
2 changed files with 8 additions and 6 deletions

View File

@ -417,9 +417,9 @@ pub const DwarfInfo = struct {
var s = io.SliceSeekableInStream.init(di.debug_info);
var this_unit_offset: u64 = 0;
while (true) {
while (this_unit_offset < try s.seekable_stream.getEndPos()) {
s.seekable_stream.seekTo(this_unit_offset) catch |err| switch (err) {
error.EndOfStream => return,
error.EndOfStream => unreachable,
else => return err,
};
@ -445,6 +445,8 @@ pub const DwarfInfo = struct {
while ((try s.seekable_stream.getPos()) < next_unit_pos) {
const die_obj = (try di.parseDie(&s.stream, abbrev_table, is_64)) orelse continue;
defer die_obj.attrs.deinit();
const after_die_offset = try s.seekable_stream.getPos();
switch (die_obj.tag_id) {
@ -520,9 +522,9 @@ pub const DwarfInfo = struct {
var s = io.SliceSeekableInStream.init(di.debug_info);
var this_unit_offset: u64 = 0;
while (true) {
while (this_unit_offset < try s.seekable_stream.getEndPos()) {
s.seekable_stream.seekTo(this_unit_offset) catch |err| switch (err) {
error.EndOfStream => return,
error.EndOfStream => unreachable,
else => return err,
};

View File

@ -73,7 +73,7 @@ pub const SliceSeekableInStream = struct {
fn seekToFn(in_stream: *SeekableInStream, pos: u64) SeekError!void {
const self = @fieldParentPtr(Self, "seekable_stream", in_stream);
const usize_pos = @intCast(usize, pos);
if (usize_pos >= self.slice.len) return error.EndOfStream;
if (usize_pos > self.slice.len) return error.EndOfStream;
self.pos = usize_pos;
}
@ -86,7 +86,7 @@ pub const SliceSeekableInStream = struct {
self.pos -= abs_amt;
} else {
const usize_amt = @intCast(usize, amt);
if (self.pos + usize_amt >= self.slice.len) return error.EndOfStream;
if (self.pos + usize_amt > self.slice.len) return error.EndOfStream;
self.pos += usize_amt;
}
}