From patchwork Mon Mar 30 16:40:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 39075 From: gprocida@google.com (Giuliano Procida) Date: Mon, 30 Mar 2020 17:40:41 +0100 Subject: [PATCH] abg-dwarf-reader.cc: Avoid division by zero. Message-ID: <20200330164041.64666-1-gprocida@google.com> 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 --- src/abg-dwarf-reader.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index 10ca1232..249e196d 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -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"; } }