From: Wilfried Goesgens Date: Sat, 21 Jun 2014 19:14:28 +0000 (+0200) Subject: Statsd: avoid doing a division by zero when calculating the average if we didn't... X-Git-Tag: collectd-5.5.0~256^2~1 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=804ef69e8163aa3de6652d52f89935444accbb4f;hp=ea47de8419ab9eaa13e06271677b25bac8e1f57d;p=collectd.git Statsd: avoid doing a division by zero when calculating the average if we didn't get any values. --- diff --git a/src/utils_latency.c b/src/utils_latency.c index 94da2112..bfe91fd8 100644 --- a/src/utils_latency.c +++ b/src/utils_latency.c @@ -128,7 +128,7 @@ cdtime_t latency_counter_get_average (latency_counter_t *lc) /* {{{ */ { double average; - if (lc == NULL) + if ((lc == NULL) || (lc->num == 0)) return (0); average = CDTIME_T_TO_DOUBLE (lc->sum) / ((double) lc->num);