]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
histogram.h: fix potential div by zero
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Fri, 28 Feb 2014 23:19:58 +0000 (00:19 +0100)
committerDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Fri, 28 Feb 2014 23:19:58 +0000 (00:19 +0100)
CID 1188131 (#1 of 1): Division or modulo by zero (DIVIDE_BY_ZERO)
 divide_by_zero: In expression "lower_sum * 1000000UL / total", division
 by expression "total" which may be zero has undefined behavior

Added check for non zero total.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
src/common/histogram.h

index 8d1ad8ea29a3b702c5a378635525c78cf70a1924..bdbd75ca132a2cdaaa7ff3fbdebab0fd47f8b5c8 100644 (file)
@@ -94,8 +94,10 @@ public:
        lower_sum += h[i];
       total += h[i];
     }
-    *lower = lower_sum * 1000000 / total;
-    *upper = upper_sum * 1000000 / total;
+    if (total > 0) {
+      *lower = lower_sum * 1000000 / total;
+      *upper = upper_sum * 1000000 / total;
+    }
     return 0;
   }