Skip to content

Commit

Permalink
read: fix parse for empty DWP index
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc committed Apr 2, 2024
1 parent 7294ff0 commit 47726d9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions crates/examples/src/bin/dwarfdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ fn dump_dwp<R: Reader, W: Write + Send>(
where
R::Endian: Send + Sync,
{
if dwp.cu_index.unit_count() != 0 {
if dwp.cu_index.version() != 0 {
writeln!(
w,
"\n.debug_cu_index: version = {}, sections = {}, units = {}, slots = {}",
Expand All @@ -1113,7 +1113,7 @@ where
}
}

if dwp.tu_index.unit_count() != 0 {
if dwp.tu_index.version() != 0 {
writeln!(
w,
"\n.debug_tu_index: version = {}, sections = {}, units = {}, slots = {}",
Expand Down
6 changes: 4 additions & 2 deletions src/read/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl<R: Reader> UnitIndex<R> {
fn parse(mut input: R) -> Result<UnitIndex<R>> {
if input.is_empty() {
return Ok(UnitIndex {
version: 5,
version: 0,
section_count: 0,
unit_count: 0,
slot_count: 0,
Expand Down Expand Up @@ -166,7 +166,7 @@ impl<R: Reader> UnitIndex<R> {
let section_count = input.read_u32()?;
let unit_count = input.read_u32()?;
let slot_count = input.read_u32()?;
if slot_count == 0 || slot_count & (slot_count - 1) != 0 || slot_count <= unit_count {
if slot_count != 0 && (slot_count & (slot_count - 1) != 0 || slot_count <= unit_count) {
return Err(Error::InvalidIndexSlotCount);
}

Expand Down Expand Up @@ -280,6 +280,8 @@ impl<R: Reader> UnitIndex<R> {
}

/// Return the version.
///
/// Defaults to 0 for empty sections.
pub fn version(&self) -> u16 {
self.version
}
Expand Down

0 comments on commit 47726d9

Please sign in to comment.