CID 716904: Division or modulo by zero (DIVIDE_BY_ZERO)
At (4): In expression "(float)weight[i] / (float)total_weight", division by expression "total_weight" which may be zero has undefined behavior.
At (8): On this path, function call "this->crush->get_max_devices()" has return value of 0
CID 716905: Division or modulo by zero (DIVIDE_BY_ZERO)
At (9): In expression "lrand48() % this->crush->get_max_devices()" modulo by expression "this->crush->get_max_devices()" which may be zero has undefined behavior.
Signed-off-by: Sage Weil <sage@inktank.com>
for (unsigned i = 0; i < weight.size(); i++)
total_weight += weight[i];
+ if (total_weight == 0 ||
+ crush.get_max_devices() == 0)
+ return -EINVAL;
+
// compute each device's proportional weight
vector<float> proportional_weights( weight.size() );
- for (unsigned i = 0; i < weight.size(); i++)
+ for (unsigned i = 0; i < weight.size(); i++) {
proportional_weights[i] = (float) weight[i] / (float) total_weight;
+ }
// determine the real maximum number of devices to return
int devices_requested = min(maxout, get_maximum_affected_by_rule(ruleno));