From 7eefe85cf53ef58349fb44af2ac60d7ebb9f5960 Mon Sep 17 00:00:00 2001 From: Danny Al-Gaaf Date: Sat, 1 Mar 2014 00:19:58 +0100 Subject: [PATCH] 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 --- src/common/histogram.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/common/histogram.h b/src/common/histogram.h index 8d1ad8ea29a3b..bdbd75ca132a2 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; } -- 2.39.5