X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Futils_latency.c;h=dfdef6115f249f1c9f66a74467192a667e94a325;hb=491b8f0185c63c662bb3f395630a6d8b9913b49e;hp=96ce8e31e64c4289a7f2c0fd8ce11e8765fb3fed;hpb=83bd30070f226d86a9c1e6e294abea2879581a15;p=collectd.git diff --git a/src/utils_latency.c b/src/utils_latency.c index 96ce8e31..dfdef611 100644 --- a/src/utils_latency.c +++ b/src/utils_latency.c @@ -209,7 +209,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); @@ -227,7 +227,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. */