Fix a division by zero bug in isc_histo
This can occur when calculating the standard deviation of an empty histogram.
This commit is contained in:
@@ -474,7 +474,7 @@ isc_histo_moments(const isc_histo_t *hg, double *pm0, double *pm1,
|
||||
|
||||
OUTARG(pm0, pop);
|
||||
OUTARG(pm1, mean);
|
||||
OUTARG(pm2, sqrt(sigma / pop));
|
||||
OUTARG(pm2, (pop > 0) ? sqrt(sigma / pop) : 0.0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -146,7 +146,7 @@ ISC_RUN_TEST_IMPL(quantiles) {
|
||||
for (uint bits = ISC_HISTO_MINBITS; bits <= ISC_HISTO_MAXBITS; bits++) {
|
||||
isc_result_t result;
|
||||
uint64_t min, max, count;
|
||||
double pop;
|
||||
double pop, mean, sd;
|
||||
uint key;
|
||||
|
||||
isc_nanosecs_t start = isc_time_monotonic();
|
||||
@@ -154,6 +154,12 @@ ISC_RUN_TEST_IMPL(quantiles) {
|
||||
isc_histo_t *hg = NULL;
|
||||
isc_histo_create(mctx, bits, &hg);
|
||||
|
||||
/* ensure empty histogram does not divide by zero */
|
||||
isc_histo_moments(hg, &pop, &mean, &sd);
|
||||
assert_true(pop == 0.0);
|
||||
assert_true(mean == 0.0);
|
||||
assert_true(sd == 0.0);
|
||||
|
||||
for (key = 0; isc_histo_get(hg, key, &min, &max, &count) ==
|
||||
ISC_R_SUCCESS;
|
||||
key++)
|
||||
|
||||
Reference in New Issue
Block a user