X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmatch_hashed.c;h=c4983c2ed056a0a455dc38131a3174876c1fb085;hb=d59524524af36bf9e3eb6108d21744076c79701d;hp=a42439c04bea05c0734a45e58188869f9e7ef279;hpb=362a519e00d50fc3657d485135075f753ec71bab;p=collectd.git diff --git a/src/match_hashed.c b/src/match_hashed.c index a42439c0..c4983c2e 100644 --- a/src/match_hashed.c +++ b/src/match_hashed.c @@ -25,6 +25,7 @@ **/ #include "collectd.h" + #include "common.h" #include "filter_chain.h" @@ -98,7 +99,6 @@ static int mh_config_match (const oconfig_item_t *ci, /* {{{ */ static int mh_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ { mh_match_t *m; - int i; m = calloc (1, sizeof (*m)); if (m == NULL) @@ -107,7 +107,7 @@ static int mh_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ return (-ENOMEM); } - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -149,8 +149,6 @@ static int mh_match (const data_set_t __attribute__((unused)) *ds, /* {{{ */ { mh_match_t *m; uint32_t hash_val; - const char *host_ptr; - size_t i; if ((user_data == NULL) || (*user_data == NULL)) return (-1); @@ -159,14 +157,14 @@ static int mh_match (const data_set_t __attribute__((unused)) *ds, /* {{{ */ hash_val = 0; - for (host_ptr = vl->host; *host_ptr != 0; host_ptr++) + for (const char *host_ptr = vl->host; *host_ptr != 0; host_ptr++) { /* 2184401929 is some appropriately sized prime number. */ hash_val = (hash_val * UINT32_C (2184401929)) + ((uint32_t) *host_ptr); } DEBUG ("hashed match: host = %s; hash_val = %"PRIu32";", vl->host, hash_val); - for (i = 0; i < m->matches_num; i++) + for (size_t i = 0; i < m->matches_num; i++) if ((hash_val % m->matches[i].total) == m->matches[i].match) return (FC_MATCH_MATCHES);