projects
/
privoxy.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
4622b68
)
Let get_percentage() show 0 of x as 0% even if x is 0 as well
author
Fabian Keil
<fk@fabiankeil.de>
Fri, 27 Jul 2012 17:37:22 +0000
(17:37 +0000)
committer
Fabian Keil
<fk@fabiankeil.de>
Fri, 27 Jul 2012 17:37:22 +0000
(17:37 +0000)
tools/privoxy-log-parser.pl
patch
|
blob
|
history
diff --git
a/tools/privoxy-log-parser.pl
b/tools/privoxy-log-parser.pl
index
1ebd659
..
766f6c6
100755
(executable)
--- a/
tools/privoxy-log-parser.pl
+++ b/
tools/privoxy-log-parser.pl
@@
-8,7
+8,7
@@
#
# http://www.fabiankeil.de/sourcecode/privoxy-log-parser/
#
#
# http://www.fabiankeil.de/sourcecode/privoxy-log-parser/
#
-# $Id: privoxy-log-parser.pl,v 1.13
2 2012/07/23 12:40:08
fabiankeil Exp $
+# $Id: privoxy-log-parser.pl,v 1.13
3 2012/07/27 17:37:00
fabiankeil Exp $
#
# TODO:
# - LOG_LEVEL_CGI, LOG_LEVEL_ERROR, LOG_LEVEL_WRITE content highlighting
#
# 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;
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 "NaN" if ($big eq 0);
+
return sprintf("%.2f%%", $small / $big * 100);
}
return sprintf("%.2f%%", $small / $big * 100);
}