From 3c208e761657829afd174240bcac47c8ccfad71f Mon Sep 17 00:00:00 2001 From: Prashant D Date: Thu, 2 Nov 2017 11:30:51 -0700 Subject: [PATCH] HistogramStat: Handle divide by zero situation Summary: The num() might return cur_num as 0 and we are making sure that cur_num will not be 0 down the path. The mult variable is being set to 100.0/cur_num which makes program crash when cur_num is 0. Closes https://github.com/facebook/rocksdb/pull/3105 Differential Revision: D6222594 Pulled By: ajkr fbshipit-source-id: 986154709897ff4dbbeb0e8aa81eb8c0b2a2db76 --- monitoring/histogram.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/monitoring/histogram.cc b/monitoring/histogram.cc index d2b7ff844..4970df7bd 100644 --- a/monitoring/histogram.cc +++ b/monitoring/histogram.cc @@ -202,6 +202,7 @@ std::string HistogramStat::ToString() const { Percentile(99.99)); r.append(buf); r.append("------------------------------------------------------\n"); + if (cur_num == 0) return r; // all buckets are empty const double mult = 100.0 / cur_num; uint64_t cumulative_sum = 0; for (unsigned int b = 0; b < num_buckets_; b++) {