X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fwrite_riemann_threshold.c;h=d393994b6a7f8820699250a4d8d9bccd6fd86026;hb=6d8031d73b7c1d874d7afa4cad2f248c4073764d;hp=b1f7297eec9b06e90d03df594599b87e5418b979;hpb=f7b05ebf3311b4c6cb5289f1f7cd8ee02918ef92;p=collectd.git diff --git a/src/write_riemann_threshold.c b/src/write_riemann_threshold.c index b1f7297e..d393994b 100644 --- a/src/write_riemann_threshold.c +++ b/src/write_riemann_threshold.c @@ -25,11 +25,8 @@ * Andrés J. Díaz **/ -#include -#include -#include - #include "collectd.h" + #include "common.h" #include "plugin.h" #include "utils_avltree.h" @@ -37,6 +34,8 @@ #include "utils_threshold.h" #include "write_riemann_threshold.h" +#include + /* * Threshold management * ==================== @@ -134,7 +133,6 @@ static int ut_check_one_threshold (const data_set_t *ds, int *statuses) { /* {{{ */ int ret = -1; - int i; int status; gauge_t values_copy[ds->ds_num]; @@ -154,7 +152,7 @@ static int ut_check_one_threshold (const data_set_t *ds, } /* Prepare `sum' and `num'. */ - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) if (!isnan (values[i])) { num++; @@ -164,17 +162,17 @@ static int ut_check_one_threshold (const data_set_t *ds, if ((num == 0) /* All data sources are undefined. */ || (sum == 0.0)) /* Sum is zero, cannot calculate percentage. */ { - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) values_copy[i] = NAN; } else /* We can actually calculate the percentage. */ { - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) values_copy[i] = 100.0 * values[i] / sum; } } /* if (UT_FLAG_PERCENTAGE) */ - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { status = ut_check_one_data_source (ds, vl, th, values_copy, i); if (status != -1) { @@ -203,7 +201,9 @@ int write_riemann_threshold_check (const data_set_t *ds, const value_list_t *vl, gauge_t *values; int status; + assert (vl->values_len > 0); memset(statuses, 0, vl->values_len * sizeof(*statuses)); + if (threshold_tree == NULL) return 0;