From 318e735fdfc3e3d7d866b96b98e376a9ffef9517 Mon Sep 17 00:00:00 2001 From: ckolivas Date: Wed, 9 Jul 2014 12:35:40 +0300 Subject: [PATCH] Put sanity upper limit on exponent function used in decay_time --- src/libckpool.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libckpool.c b/src/libckpool.c index 01dca0ac..72df31d8 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -1328,11 +1328,15 @@ double tvdiff(tv_t *end, tv_t *start) /* Create an exponentially decaying average over interval */ void decay_time(double *f, double fadd, double fsecs, double interval) { - double ftotal, fprop; + double ftotal, fprop, dexp; if (fsecs <= 0) return; - fprop = 1.0 - 1 / (exp(fsecs / interval)); + dexp = fsecs / interval; + /* Put Sanity bound on how large the denominator can get */ + if (unlikely(dexp > 36)) + dexp = 36; + fprop = 1.0 - 1 / exp(dexp); ftotal = 1.0 + fprop; *f += (fadd / fsecs * fprop); *f /= ftotal;