Skip to content

Commit

Permalink
HistogramStat: Handle divide by zero situation
Browse files Browse the repository at this point in the history
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 facebook#3105

Differential Revision: D6222594

Pulled By: ajkr

fbshipit-source-id: 986154709897ff4dbbeb0e8aa81eb8c0b2a2db76
  • Loading branch information
Prashant D authored and facebook-github-bot committed Nov 2, 2017
1 parent 25fbd9a commit 3c208e7
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions monitoring/histogram.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down

0 comments on commit 3c208e7

Please sign in to comment.