Skip to content

Commit

Permalink
scripts/bloat-o-meter: don't fail with division by 0
Browse files Browse the repository at this point in the history
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.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Andy Shevchenko <[email protected]>
Cc: Alexey Dobriyan <[email protected]>
Cc: Vaneet Narang <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
andy-shev authored and torvalds committed Nov 30, 2017
1 parent d5dabd6 commit edbddb8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions scripts/bloat-o-meter
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ def print_result(symboltype, symbolformat, argc):
for d, n in delta:
if d: print("%-40s %7s %7s %+7d" % (n, old.get(n,"-"), new.get(n,"-"), d))

print("Total: Before=%d, After=%d, chg %+.2f%%" % \
(otot, ntot, (ntot - otot)*100.0/otot))
if otot:
percent = (ntot - otot) * 100.0 / otot
else:
percent = 0
print("Total: Before=%d, After=%d, chg %+.2f%%" % (otot, ntot, percent))

if sys.argv[1] == "-c":
print_result("Function", "tT", 3)
Expand Down

0 comments on commit edbddb8

Please sign in to comment.