X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fthreshold.c;h=bbd4091371dcf0f88c695d1650b3447cfe5631fa;hb=aef788ac8927ffa74429daaffb572566fae782ec;hp=45ee3b4d02c61b722419577ee607580dcdb4cb26;hpb=22651d8d4dc49e24bbac2cd34e0642dcf3639c97;p=collectd.git diff --git a/src/threshold.c b/src/threshold.c index 45ee3b4d..bbd40913 100644 --- a/src/threshold.c +++ b/src/threshold.c @@ -24,15 +24,13 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" #include "utils_avltree.h" #include "utils_cache.h" #include "utils_threshold.h" -#include -#include - /* * Threshold management * ==================== @@ -70,7 +68,7 @@ static int ut_threshold_add (const threshold_t *th) return (-1); } - th_copy = (threshold_t *) malloc (sizeof (threshold_t)); + th_copy = malloc (sizeof (*th_copy)); if (th_copy == NULL) { sfree (name_copy); @@ -78,7 +76,6 @@ static int ut_threshold_add (const threshold_t *th) return (-1); } memcpy (th_copy, th, sizeof (threshold_t)); - th_ptr = NULL; DEBUG ("ut_threshold_add: Adding entry `%s'", name); @@ -553,7 +550,7 @@ static int ut_report_state (const data_set_t *ds, { gauge_t value; gauge_t sum; - int i; + size_t i; sum = 0.0; for (i = 0; i < vl->values_len; i++) @@ -701,7 +698,7 @@ static int ut_check_one_threshold (const data_set_t *ds, { /* {{{ */ int ret = -1; int ds_index = -1; - int i; + size_t i; gauge_t values_copy[ds->ds_num]; memcpy (values_copy, values, sizeof (values_copy)); @@ -874,11 +871,9 @@ static int ut_config (oconfig_item_t *ci) int status = 0; int old_size = c_avl_size (threshold_tree); - threshold_t th; - if (threshold_tree == NULL) { - threshold_tree = c_avl_create ((void *) strcmp); + threshold_tree = c_avl_create ((int (*) (const void *, const void *)) strcmp); if (threshold_tree == NULL) { ERROR ("ut_config: c_avl_create failed."); @@ -886,15 +881,13 @@ static int ut_config (oconfig_item_t *ci) } } - memset (&th, '\0', sizeof (th)); - th.warning_min = NAN; - th.warning_max = NAN; - th.failure_min = NAN; - th.failure_max = NAN; - - th.hits = 0; - th.hysteresis = 0; - th.flags = UT_FLAG_INTERESTING; /* interesting by default */ + threshold_t th = { + .warning_min = NAN, + .warning_max = NAN, + .failure_min = NAN, + .failure_max = NAN, + .flags = UT_FLAG_INTERESTING /* interesting by default */ + }; for (i = 0; i < ci->children_num; i++) {