From 2f911f75a12f5af88769956585ac1ceb107e4ee5 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 6 May 2014 08:32:42 +0200 Subject: [PATCH] Fix division by zero in Icinga\Util\Format refs #6125 --- library/Icinga/Util/Format.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/library/Icinga/Util/Format.php b/library/Icinga/Util/Format.php index a7c0ee0e3..d7772211f 100644 --- a/library/Icinga/Util/Format.php +++ b/library/Icinga/Util/Format.php @@ -153,14 +153,19 @@ class Format $value = abs($value); $sign = '-'; } - $pow = floor(log($value, $base)); - $result = $value / pow($base, $pow); + + if ($value == 0) { + $pow = $result = 0; + } else { + $pow = floor(log($value, $base)); + $result = $value / pow($base, $pow); + } // 1034.23 looks better than 1.03, but 2.03 is fine: if ($pow > 0 && $result < 2) { - $pow--; - $result = $value / pow($base, $pow); + $result = $value / pow($base, --$pow); } + return sprintf( '%s%0.2f %s', $sign,