X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Futils_latency.c;h=c6a1ff6669185746d9ea1da8e0e56553946f10d9;hb=08a2128ac248150b50f9c54c9c71f573e54df3c3;hp=470fbb8dac01fcd069b5668d288b7cca5a75f771;hpb=4016dcd8e914a98301a737403b7fa1b38c02d4b4;p=collectd.git diff --git a/src/utils_latency.c b/src/utils_latency.c index 470fbb8d..c6a1ff66 100644 --- a/src/utils_latency.c +++ b/src/utils_latency.c @@ -1,6 +1,6 @@ /** * collectd - src/utils_latency.c - * Copyright (C) 2013 Florian Forster + * Copyright (C) 2013 Florian Forster * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -117,6 +117,7 @@ latency_counter_t *latency_counter_create () /* {{{ */ lc = malloc (sizeof (*lc)); if (lc == NULL) return (NULL); + memset (lc, 0, sizeof (*lc)); latency_counter_reset (lc); lc->bin_width = HISTOGRAM_DEFAULT_BIN_WIDTH; @@ -227,7 +228,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. */