From b7cf6030ae95b8b2c7e2faecd779019c9237d372 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 28 Sep 2012 06:57:58 -0700 Subject: [PATCH] crushtester: avoid divide by zero 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 --- src/crush/CrushTester.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/crush/CrushTester.cc b/src/crush/CrushTester.cc index 6acde9f03b912..270c4e39f5ec8 100644 --- a/src/crush/CrushTester.cc +++ b/src/crush/CrushTester.cc @@ -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; -- 2.47.3