Merge remote-tracking branch 'github/pr/682'
[collectd.git] / src / utils_latency.c
index 4e1fba6..91ddd5f 100644 (file)
@@ -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. */