diff mbox series

abg-dwarf-reader.cc: Avoid division by zero.

Message ID 20200330164041.64666-1-gprocida@google.com
State Committed
Headers show
Series abg-dwarf-reader.cc: Avoid division by zero. | expand

Commit Message

Giuliano Procida March 30, 2020, 4:40 p.m. UTC
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

Dodji Seketeli April 1, 2020, 5:45 p.m. UTC | #1
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,
diff mbox series

Patch

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";
       }
 
   }