Skip to content

Commit 1dcaa5b

Browse files
nagisaDavid Wood
authored andcommitted
Check the iterator type instead of a bool flag
Having two distinct values representing the same information can lead to accidental divergence and be a source of bugs further down the line.
1 parent 1b6c502 commit 1dcaa5b

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

thorin/src/package.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ impl<'file> InProgressDwarfPackage<'file> {
580580

581581
for section in input.sections() {
582582
let data;
583-
let (is_debug_types, mut iter) = match section.name() {
583+
let mut iter = match section.name() {
584584
Ok(".debug_info.dwo" | ".zdebug_info.dwo")
585585
// Report an error if a input DWARF package has multiple `.debug_info`
586586
// sections.
@@ -591,11 +591,8 @@ impl<'file> InProgressDwarfPackage<'file> {
591591
Ok(".debug_info.dwo" | ".zdebug_info.dwo") => {
592592
data = section.compressed_data()?.decompress()?;
593593
seen_debug_info = true;
594-
(
595-
false,
596-
UnitHeaderIterator::DebugInfo(
597-
gimli::DebugInfo::new(&data, self.endian).units(),
598-
),
594+
UnitHeaderIterator::DebugInfo(
595+
gimli::DebugInfo::new(&data, self.endian).units(),
599596
)
600597
}
601598
Ok(".debug_types.dwo" | ".zdebug_types.dwo")
@@ -608,11 +605,8 @@ impl<'file> InProgressDwarfPackage<'file> {
608605
Ok(".debug_types.dwo" | ".zdebug_types.dwo") => {
609606
data = section.compressed_data()?.decompress()?;
610607
seen_debug_types = true;
611-
(
612-
true,
613-
UnitHeaderIterator::DebugTypes(
614-
gimli::DebugTypes::new(&data, self.endian).units(),
615-
),
608+
UnitHeaderIterator::DebugTypes(
609+
gimli::DebugTypes::new(&data, self.endian).units(),
616610
)
617611
}
618612
_ => continue,
@@ -658,11 +652,11 @@ impl<'file> InProgressDwarfPackage<'file> {
658652
.map_err(Error::DecompressData)?
659653
.ok_or(Error::EmptyUnit(id.index()))?;
660654

661-
let (debug_info, debug_types) = match id {
662-
DwarfObject::Type(_) if is_debug_types => {
655+
let (debug_info, debug_types) = match (&iter, id) {
656+
(UnitHeaderIterator::DebugTypes(_), DwarfObject::Type(_)) => {
663657
(None, self.obj.append_to_debug_types(data))
664658
}
665-
DwarfObject::Compilation(_) | DwarfObject::Type(_) => {
659+
(_, DwarfObject::Compilation(_) | DwarfObject::Type(_)) => {
666660
(self.obj.append_to_debug_info(data), None)
667661
}
668662
};

0 commit comments

Comments
 (0)