History

scripts/bloat-o-meter: don't fail with division by 0

Under some circumstances it's possible to get a divider 0 which crashes the script. Traceback (most recent call last): File "linux/scripts/bloat-o-meter", line 98, in <module> print_result("Function", "tTdDbBrR", 2) File "linux/scripts/bloat-o-meter", line 87, in print_result (otot, ntot, (ntot - otot)*100.0/otot)) ZeroDivisionError: float division by zero Hide this by checking the divider first.

Andy Shevchenko committed 8 years ago

Commit edbddb81 parent d5dabd61 file · +5 −2Browse files

Unified · Split

scripts/bloat-o-meter+5−2
@@ -83,8 +83,11 @@ def print_result(symboltype, symbolformat, argc): · 82 unmodified lines
8383 for d, n in delta:
8484 if d: print("%-40s %7s %7s %+7d" % (n, old.get(n,"-"), new.get(n,"-"), d))
8585
86− print("Total: Before=%d, After=%d, chg %+.2f%%" % \
87− (otot, ntot, (ntot - otot)*100.0/otot))
86+ if otot:
87+ percent = (ntot - otot) * 100.0 / otot
88+ else:
89+ percent = 0
90+ print("Total: Before=%d, After=%d, chg %+.2f%%" % (otot, ntot, percent))
8891
8992 if sys.argv[1] == "-c":
9093 print_result("Function", "tT", 3)