]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crushtester: avoid divide by zero
authorSage Weil <sage@inktank.com>
Fri, 28 Sep 2012 13:57:58 +0000 (06:57 -0700)
committerSage Weil <sage@inktank.com>
Fri, 28 Sep 2012 20:18:05 +0000 (13:18 -0700)
CID 716906: Division or modulo by zero (DIVIDE_BY_ZERO)
At (214): In expression "(float)weight[i] / (float)total_weight", division by expression "total_weight" which may be zero has undefined behavior.

Signed-off-by: Sage Weil <sage@inktank.com>
src/crush/CrushTester.cc

index 6acde9f03b912ea06c64c194e6a53ccfd4904274..270c4e39f5ec8f8507528f79df74e21350d14817 100644 (file)
@@ -430,10 +430,12 @@ int CrushTester::test()
 
       // get the total weight of the system
       int total_weight = 0;
-
       for (unsigned i = 0; i < per.size(); i++)
         total_weight += weight[i];
 
+      if (total_weight == 0)
+       continue;
+
       // compute the expected number of objects stored per device in the absence of weighting
       float expected_objects = min(nr, get_maximum_affected_by_rule(r)) * num_objects;