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
This commit is contained in:
Prashant D 2017-11-02 11:30:51 -07:00 committed by Facebook Github Bot
parent 25fbd9a996
commit 3c208e7616

View File

@ -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++) {