abg-dwarf-reader.cc: Avoid division by zero.
Commit Message
The DWARF reader could divide by zero when emitting statistics about
late canonicalisation of types. This is undefined behaviour but
typically results in process termination.
* src/abg-dwarf-reader.cc (perform_late_type_canonicalizing):
If total is zero, don't try to output percentages using it as
a divisor.
Signed-off-by: Giuliano Procida <gprocida@google.com>
---
src/abg-dwarf-reader.cc | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
Comments
Giuliano Procida <gprocida@google.com> a ?crit:
> The DWARF reader could divide by zero when emitting statistics about
> late canonicalisation of types. This is undefined behaviour but
> typically results in process termination.
>
> * src/abg-dwarf-reader.cc (perform_late_type_canonicalizing):
> If total is zero, don't try to output percentages using it as
> a divisor.
Applied to master, thanks!
Cheers,
@@ -5849,11 +5849,15 @@ public:
<< elf_path()
<< "\n";
cerr << " # late canonicalized types: "
- << num_canonicalized
- << " (" << num_canonicalized * 100 / total << "%)\n"
+ << num_canonicalized;
+ if (total)
+ cerr << " (" << num_canonicalized * 100 / total << "%)";
+ cerr << "\n"
<< " # missed canonicalization opportunities: "
- << num_missed
- << " (" << num_missed * 100 / total << "%)\n";
+ << num_missed;
+ if (total)
+ cerr << " (" << num_missed * 100 / total << "%)";
+ cerr << "\n";
}
}