From 409c955608653576bde3402c87232b4e25648d4a Mon Sep 17 00:00:00 2001 From: Danny Al-Gaaf Date: Thu, 4 Sep 2014 16:09:01 +0200 Subject: [PATCH] OSDMonitor.cc: fix potential division by zero Fix for: CID 1232602 (#1 of 1): Division or modulo by zero (DIVIDE_BY_ZERO) divide_by_zero: In expression num_pg_copies / num_osds, division by expression num_osds which may be zero has undefined behavior. Signed-off-by: Danny Al-Gaaf --- src/mon/OSDMonitor.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index c62c596f74b7..25a5bc7fc05c 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -485,7 +485,7 @@ int OSDMonitor::reweight_by_utilization(int oload, std::string& out_str, } } - if (num_pg_copies / num_osds < g_conf->mon_reweight_min_pgs_per_osd) { + if (!num_osds || (num_pg_copies / num_osds < g_conf->mon_reweight_min_pgs_per_osd)) { ostringstream oss; oss << "Refusing to reweight: we only have " << num_pg_copies << " PGs across " << num_osds << " osds!\n"; -- 2.47.3