X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_latency.c;h=91ddd5fd92485c0a02d6642b56ce346334f40b50;hb=8f4a48a804f9d95010cf5ad469e4729cebc3e0e9;hp=4e1fba627a8b6777a08e433c76ee397fc10144bc;hpb=01f04ae581be93c6434a858bfaabc5e42237a6fe;p=collectd.git diff --git a/src/utils_latency.c b/src/utils_latency.c index 4e1fba62..91ddd5fd 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); @@ -146,7 +146,7 @@ cdtime_t latency_counter_get_percentile (latency_counter_t *lc, int sum; size_t i; - if ((lc == NULL) || !((percent > 0.0) && (percent < 100.0))) + if ((lc == NULL) || (lc->num == 0) || !((percent > 0.0) && (percent < 100.0))) return (0); /* Find index i so that at least "percent" events are within i+1 ms. */