From: Fabian Keil <fk@fabiankeil.de>
Date: Fri, 27 Jul 2012 17:37:22 +0000 (+0000)
Subject: Let get_percentage() show 0 of x as 0% even if x is 0 as well
X-Git-Tag: v_3_0_20~295
X-Git-Url: http://www.privoxy.org/gitweb/%22https:/faq/static/man-page/static/gitweb.js?a=commitdiff_plain;h=df33b118a5cda48cf8a69761c4b5b3cfd9534850;p=privoxy.git

Let get_percentage() show 0 of x as 0% even if x is 0 as well
---

diff --git a/tools/privoxy-log-parser.pl b/tools/privoxy-log-parser.pl
index 1ebd6597..766f6c69 100755
--- a/tools/privoxy-log-parser.pl
+++ b/tools/privoxy-log-parser.pl
@@ -8,7 +8,7 @@
 #
 # http://www.fabiankeil.de/sourcecode/privoxy-log-parser/
 #
-# $Id: privoxy-log-parser.pl,v 1.132 2012/07/23 12:40:08 fabiankeil Exp $
+# $Id: privoxy-log-parser.pl,v 1.133 2012/07/27 17:37:00 fabiankeil Exp $
 #
 # TODO:
 #       - LOG_LEVEL_CGI, LOG_LEVEL_ERROR, LOG_LEVEL_WRITE content highlighting
@@ -2041,7 +2041,15 @@ sub init_stats () {
 sub get_percentage ($$) {
     my $big = shift;
     my $small = shift;
+
+    # If small is 0 the percentage is always 0%.
+    # Make sure it works even if big is 0 as well.
+    return "0.00%" if ($small eq 0);
+
+    # Prevent division by zero.
+    # XXX: Is this still supposed to be reachable?
     return "NaN" if ($big eq 0);
+
     return sprintf("%.2f%%", $small / $big * 100);
 }