From: Danny Al-Gaaf Date: Fri, 28 Feb 2014 23:19:58 +0000 (+0100) Subject: histogram.h: fix potential div by zero X-Git-Tag: v0.78~108^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7eefe85cf53ef58349fb44af2ac60d7ebb9f5960;p=ceph.git histogram.h: fix potential div by zero 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 --- diff --git a/src/common/histogram.h b/src/common/histogram.h index 8d1ad8ea29a3..bdbd75ca132a 100644 --- a/src/common/histogram.h +++ b/src/common/histogram.h @@ -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; }