X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftally%2Ftally.c;h=936b5142561a9ec172fd86a96ddf88a529472842;hp=9775cb4e62a3087e070cf9cd28dab8f4b7e051af;hb=ce3198f06194b9ccd9a5d7653daa109175e1226b;hpb=9dba5bf0cb3f74bf9bcaebd8c63ceaa8c6dcbbab diff --git a/ccan/tally/tally.c b/ccan/tally/tally.c index 9775cb4e..936b5142 100644 --- a/ccan/tally/tally.c +++ b/ccan/tally/tally.c @@ -302,8 +302,9 @@ static int64_t divls64(int64_t u1, uint64_t u0, int64_t v) vneg = v >> 63; /* -1 if v < 0. */ v = (v ^ vneg) - vneg; /* Absolute value of v. */ - if ((uint64_t)u1 >= (uint64_t)v) + if ((uint64_t)u1 >= (uint64_t)v) { goto overflow; + } q = divlu64(u1, u0, v); @@ -321,8 +322,9 @@ static int64_t divls64(int64_t u1, uint64_t u0, int64_t v) ssize_t tally_mean(const struct tally *tally) { size_t count = tally_num(tally); - if (!count) + if (!count) { return 0; + } if (sizeof(tally->total[0]) == sizeof(uint32_t)) { /* Use standard 64-bit arithmetic. */ @@ -365,10 +367,11 @@ static ssize_t bucket_range(const struct tally *tally, unsigned b, size_t *err) ssize_t min, max; min = bucket_min(tally->min, tally->step_bits, b); - if (b == tally->buckets - 1) + if (b == tally->buckets - 1) { max = tally->max; - else + } else { max = bucket_min(tally->min, tally->step_bits, b+1) - 1; + } /* FIXME: Think harder about cumulative error; is this enough?. */ *err = (max - min + 1) / 2;