From 2761915bed8c6caea41018be3e675aa712cc0b0a Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Tue, 2 Aug 2016 20:19:37 +0200 Subject: [PATCH] treewide: declare loop variable in loop expression --- src/aggregation.c | 14 +++----- src/amqp.c | 14 +++----- src/apache.c | 9 ++--- src/apcups.c | 3 +- src/apple_sensors.c | 4 +-- src/aquaero.c | 10 ++---- src/ascent.c | 21 ++++------- src/barometer.c | 10 +++--- src/battery.c | 15 +++----- src/bind.c | 47 ++++++++---------------- src/ceph.c | 46 +++++++++++------------- src/cgroups.c | 6 ++-- src/chrony.c | 4 +-- src/collectd-nagios.c | 32 +++++++---------- src/collectd-tg.c | 3 +- src/collectdctl.c | 20 ++++------- src/cpu.c | 51 +++++++++----------------- src/cpufreq.c | 3 +- src/csv.c | 10 ++---- src/curl.c | 16 +++------ src/curl_json.c | 13 +++---- src/curl_xml.c | 27 +++++--------- src/daemon/collectd.c | 3 +- src/daemon/common.c | 30 +++++----------- src/daemon/common_test.c | 12 +++---- src/daemon/configfile.c | 58 ++++++++++-------------------- src/daemon/filter_chain.c | 27 +++++--------- src/daemon/meta_data.c | 17 +++------ src/daemon/plugin.c | 21 ++++------- src/daemon/types_list.c | 3 +- src/daemon/utils_avltree_test.c | 11 +++--- src/daemon/utils_cache.c | 30 ++++++---------- src/daemon/utils_heap_test.c | 7 ++-- src/daemon/utils_ignorelist.c | 4 +-- src/daemon/utils_match.c | 3 +- src/daemon/utils_subst_test.c | 6 ++-- src/daemon/utils_tail_match.c | 10 ++---- src/daemon/utils_time_test.c | 6 ++-- src/dbi.c | 46 +++++++++--------------- src/df.c | 7 ++-- src/disk.c | 9 ++--- src/dns.c | 7 ++-- src/drbd.c | 5 ++- src/email.c | 21 ++++------- src/ethstat.c | 11 ++---- src/exec.c | 17 +++------ src/filecount.c | 11 ++---- src/fscache.c | 3 +- src/gmond.c | 24 +++++-------- src/hddtemp.c | 7 ++-- src/interface.c | 14 ++++---- src/ipc.c | 12 +++---- src/ipmi.c | 4 +-- src/iptables.c | 7 ++-- src/ipvs.c | 7 ++-- src/java.c | 42 ++++++++-------------- src/libcollectdclient/client.c | 13 +++---- src/libcollectdclient/network.c | 7 ++-- src/libcollectdclient/network_buffer.c | 3 +- src/liboconfig/oconfig.c | 14 +++----- src/liboconfig/parser.y | 3 +- src/madwifi.c | 19 ++++------ src/match_empty_counter.c | 3 +- src/match_hashed.c | 9 ++--- src/match_regex.c | 7 ++-- src/match_timediff.c | 3 +- src/match_value.c | 19 ++++------ src/mbmon.c | 8 ++--- src/memcachec.c | 16 +++------ src/memcached.c | 10 +++--- src/memory.c | 10 ++---- src/mic.c | 9 ++--- src/modbus.c | 30 +++++----------- src/mqtt.c | 20 ++++------- src/multimeter.c | 3 +- src/mysql.c | 7 ++-- src/netapp.c | 65 ++++++++++++---------------------- src/netlink.c | 11 ++---- src/network.c | 48 +++++++++---------------- src/nfs.c | 13 +++---- src/nginx.c | 4 +-- src/notify_desktop.c | 4 +-- src/notify_email.c | 3 +- src/notify_nagios.c | 4 +-- src/ntpd.c | 9 ++--- src/nut.c | 3 +- src/olsrd.c | 4 +-- src/onewire.c | 3 +- src/openldap.c | 14 +++----- src/openvpn.c | 12 +++---- src/oracle.c | 26 +++++--------- src/perl.c | 38 +++++++------------- src/pf.c | 9 +++-- src/pinba.c | 21 ++++------- src/ping.c | 16 +++------ src/postgresql.c | 50 +++++++++----------------- src/powerdns.c | 23 ++++-------- src/processes.c | 48 ++++++++----------------- src/python.c | 26 ++++++-------- src/pyvalues.c | 12 +++---- src/redis.c | 17 +++------ src/routeros.c | 7 ++-- src/rrdcached.c | 10 ++---- src/rrdtool.c | 12 +++---- src/sensors.c | 13 +++---- src/serial.c | 3 +- src/sigrok.c | 10 ++---- src/snmp.c | 39 +++++++------------- src/statsd.c | 18 ++++------ src/swap.c | 12 +++---- src/table.c | 50 +++++++++----------------- src/tail.c | 17 +++------ src/tail_csv.c | 12 +++---- src/tape.c | 3 +- src/target_notification.c | 8 ++--- src/target_replace.c | 6 ++-- src/target_scale.c | 14 +++----- src/target_set.c | 3 +- src/tcpconns.c | 15 +++----- src/teamspeak2.c | 6 ++-- src/ted.c | 6 ++-- src/threshold.c | 24 +++++-------- src/turbostat.c | 24 +++++-------- src/utils_cmd_flush.c | 7 ++-- src/utils_cmd_getval.c | 3 +- src/utils_cmd_listval.c | 6 ++-- src/utils_crc32.c | 3 +- src/utils_curl_stats.c | 6 ++-- src/utils_db_query.c | 55 ++++++++++------------------ src/utils_dns.c | 7 ++-- src/utils_format_graphite.c | 11 ++---- src/utils_format_json.c | 18 ++++------ src/utils_format_kairosdb.c | 6 ++-- src/utils_latency.c | 3 +- src/utils_latency_test.c | 6 ++-- src/utils_mount.c | 15 +++----- src/utils_rrdcreate.c | 16 +++------ src/varnish.c | 7 ++-- src/virt.c | 59 +++++++++++++----------------- src/write_graphite.c | 10 ++---- src/write_http.c | 7 ++-- src/write_kafka.c | 6 ++-- src/write_mongodb.c | 14 +++----- src/write_redis.c | 7 ++-- src/write_riemann.c | 8 ++--- src/write_riemann_threshold.c | 9 +++-- src/write_sensu.c | 27 +++++--------- src/write_tsdb.c | 13 +++---- src/xencpu.c | 4 +-- src/zfs_arc.c | 4 +-- src/zookeeper.c | 3 +- 151 files changed, 750 insertions(+), 1478 deletions(-) diff --git a/src/aggregation.c b/src/aggregation.c index 92f34bc3..b9db500b 100644 --- a/src/aggregation.c +++ b/src/aggregation.c @@ -483,9 +483,7 @@ static void agg_lookup_free_obj_callback (void *user_obj) /* {{{ */ static int agg_config_handle_group_by (oconfig_item_t const *ci, /* {{{ */ aggregation_t *agg) { - int i; - - for (i = 0; i < ci->values_num; i++) + for (int i = 0; i < ci->values_num; i++) { char const *value; @@ -521,7 +519,6 @@ static int agg_config_aggregation (oconfig_item_t *ci) /* {{{ */ aggregation_t *agg; _Bool is_valid; int status; - int i; agg = calloc (1, sizeof (*agg)); if (agg == NULL) @@ -538,7 +535,7 @@ static int agg_config_aggregation (oconfig_item_t *ci) /* {{{ */ sstrncpy (agg->ident.type_instance, "/.*/", sizeof (agg->ident.type_instance)); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -676,8 +673,6 @@ static int agg_config_aggregation (oconfig_item_t *ci) /* {{{ */ static int agg_config (oconfig_item_t *ci) /* {{{ */ { - int i; - pthread_mutex_lock (&agg_instance_list_lock); if (lookup == NULL) @@ -694,7 +689,7 @@ static int agg_config (oconfig_item_t *ci) /* {{{ */ } } - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -712,7 +707,6 @@ static int agg_config (oconfig_item_t *ci) /* {{{ */ static int agg_read (void) /* {{{ */ { - agg_instance_t *this; cdtime_t t; int success; @@ -733,7 +727,7 @@ static int agg_read (void) /* {{{ */ return (0); } - for (this = agg_instance_list_head; this != NULL; this = this->next) + for (agg_instance_t *this = agg_instance_list_head; this != NULL; this = this->next) { int status; diff --git a/src/amqp.c b/src/amqp.c index 809d5549..89f051e8 100644 --- a/src/amqp.c +++ b/src/amqp.c @@ -528,13 +528,11 @@ static int camqp_connect (camqp_config_t *conf) /* {{{ */ static int camqp_shutdown (void) /* {{{ */ { - size_t i; - DEBUG ("amqp plugin: Shutting down %zu subscriber threads.", subscriber_threads_num); subscriber_threads_running = 0; - for (i = 0; i < subscriber_threads_num; i++) + for (size_t i = 0; i < subscriber_threads_num; i++) { /* FIXME: Sending a signal is not very elegant here. Maybe find out how * to use a timeout in the thread and check for the variable in regular @@ -822,7 +820,6 @@ static int camqp_write (const data_set_t *ds, const value_list_t *vl, /* {{{ */ } else { - size_t i; ssnprintf (routing_key, sizeof (routing_key), "collectd/%s/%s/%s/%s/%s", vl->host, vl->plugin, vl->plugin_instance, @@ -830,7 +827,7 @@ static int camqp_write (const data_set_t *ds, const value_list_t *vl, /* {{{ */ /* Switch slashes (the only character forbidden by collectd) and dots * (the separation character used by AMQP). */ - for (i = 0; routing_key[i] != 0; i++) + for (size_t i = 0; routing_key[i] != 0; i++) { if (routing_key[i] == '.') routing_key[i] = '/'; @@ -920,7 +917,6 @@ static int camqp_config_connection (oconfig_item_t *ci, /* {{{ */ { camqp_config_t *conf; int status; - int i; conf = calloc (1, sizeof (*conf)); if (conf == NULL) @@ -967,7 +963,7 @@ static int camqp_config_connection (oconfig_item_t *ci, /* {{{ */ return (status); } - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -1100,9 +1096,7 @@ static int camqp_config_connection (oconfig_item_t *ci, /* {{{ */ static int camqp_config (oconfig_item_t *ci) /* {{{ */ { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/apache.c b/src/apache.c index 59ddd8fa..650d6788 100644 --- a/src/apache.c +++ b/src/apache.c @@ -175,7 +175,6 @@ static size_t apache_header_callback (void *buf, size_t size, size_t nmemb, static int config_add (oconfig_item_t *ci) { apache_t *st; - int i; int status; st = calloc (1, sizeof (*st)); @@ -195,7 +194,7 @@ static int config_add (oconfig_item_t *ci) } assert (st->name != NULL); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -272,9 +271,8 @@ static int config_add (oconfig_item_t *ci) static int config (oconfig_item_t *ci) { int status = 0; - int i; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -465,8 +463,7 @@ static void submit_scoreboard (char *buf, apache_t *st) long long response_start = 0LL; long long response_end = 0LL; - int i; - for (i = 0; buf[i] != '\0'; i++) + for (int i = 0; buf[i] != '\0'; i++) { if (buf[i] == '.') open++; else if (buf[i] == '_') waiting++; diff --git a/src/apcups.c b/src/apcups.c index a1f23826..cc203578 100644 --- a/src/apcups.c +++ b/src/apcups.c @@ -381,10 +381,9 @@ static int apc_query_server (char const *node, char const *service, static int apcups_config (oconfig_item_t *ci) { - int i; _Bool persistent_conn_set = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/apple_sensors.c b/src/apple_sensors.c index 1c72dda5..48fbcb91 100644 --- a/src/apple_sensors.c +++ b/src/apple_sensors.c @@ -114,8 +114,6 @@ static int as_read (void) char inst[128]; int value_int; double value_double; - int i; - if (!io_master_port || (io_master_port == MACH_PORT_NULL)) return (-1); @@ -170,7 +168,7 @@ static int as_read (void) kCFStringEncodingASCII)) continue; inst[sizeof (inst) - 1] = '\0'; - for (i = 0; i < 128; i++) + for (int i = 0; i < 128; i++) { if (inst[i] == '\0') break; diff --git a/src/aquaero.c b/src/aquaero.c index ad711eee..81a4efd4 100644 --- a/src/aquaero.c +++ b/src/aquaero.c @@ -34,9 +34,7 @@ static char *conf_device = NULL; static int aquaero_config (oconfig_item_t *ci) { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -88,9 +86,8 @@ static void aquaero_submit_array (const char *type, const char *type_instance_prefix, double *value_array, int len) { char type_instance[DATA_MAX_NAME_LEN]; - int i; - for (i = 0; i < len; i++) + for (int i = 0; i < len; i++) { if (value_array[i] == AQ5_FLOAT_UNDEF) continue; @@ -107,7 +104,6 @@ static int aquaero_read (void) aq5_settings_t aq_sett; char *err_msg = NULL; char type_instance[DATA_MAX_NAME_LEN]; - int i; if (libaquaero5_poll(conf_device, &aq_data, &err_msg) < 0) { @@ -148,7 +144,7 @@ static int aquaero_read (void) AQ5_NUM_OTHER_SENSORS); /* Fans */ - for (i = 0; i < AQ5_NUM_FAN; i++) + for (int i = 0; i < AQ5_NUM_FAN; i++) { if ((aq_sett.fan_data_source[i] == NONE) || (aq_data.fan_vrm_temp[i] != AQ5_FLOAT_UNDEF)) diff --git a/src/ascent.c b/src/ascent.c index 504decc4..20fef656 100644 --- a/src/ascent.c +++ b/src/ascent.c @@ -182,20 +182,19 @@ static size_t ascent_curl_callback (void *buf, size_t size, size_t nmemb, /* {{{ static int ascent_submit_players (player_stats_t *ps) /* {{{ */ { - size_t i; gauge_t value; - for (i = 0; i < RACES_LIST_LENGTH; i++) + for (size_t i = 0; i < RACES_LIST_LENGTH; i++) if (races_list[i] != NULL) ascent_submit_gauge ("by-race", "players", races_list[i], (gauge_t) ps->races[i]); - for (i = 0; i < CLASSES_LIST_LENGTH; i++) + for (size_t i = 0; i < CLASSES_LIST_LENGTH; i++) if (classes_list[i] != NULL) ascent_submit_gauge ("by-class", "players", classes_list[i], (gauge_t) ps->classes[i]); - for (i = 0; i < GENDERS_LIST_LENGTH; i++) + for (size_t i = 0; i < GENDERS_LIST_LENGTH; i++) if (genders_list[i] != NULL) ascent_submit_gauge ("by-gender", "players", genders_list[i], (gauge_t) ps->genders[i]); @@ -329,9 +328,7 @@ static int ascent_xml_read_int (xmlDoc *doc, xmlNode *node, /* {{{ */ static int ascent_xml_sessions_plr (xmlDoc *doc, xmlNode *node, /* {{{ */ player_info_t *pi) { - xmlNode *child; - - for (child = node->xmlChildrenNode; child != NULL; child = child->next) + for (xmlNode *child = node->xmlChildrenNode; child != NULL; child = child->next) { if ((xmlStrcmp ((const xmlChar *) "comment", child->name) == 0) || (xmlStrcmp ((const xmlChar *) "text", child->name) == 0)) @@ -365,12 +362,11 @@ static int ascent_xml_sessions_plr (xmlDoc *doc, xmlNode *node, /* {{{ */ static int ascent_xml_sessions (xmlDoc *doc, xmlNode *node) /* {{{ */ { - xmlNode *child; player_stats_t ps = { .level_sum = 0 }; - for (child = node->xmlChildrenNode; child != NULL; child = child->next) + for (xmlNode *child = node->xmlChildrenNode; child != NULL; child = child->next) { if ((xmlStrcmp ((const xmlChar *) "comment", child->name) == 0) || (xmlStrcmp ((const xmlChar *) "text", child->name) == 0)) @@ -397,9 +393,7 @@ static int ascent_xml_sessions (xmlDoc *doc, xmlNode *node) /* {{{ */ static int ascent_xml_status (xmlDoc *doc, xmlNode *node) /* {{{ */ { - xmlNode *child; - - for (child = node->xmlChildrenNode; child != NULL; child = child->next) + for (xmlNode *child = node->xmlChildrenNode; child != NULL; child = child->next) { if ((xmlStrcmp ((const xmlChar *) "comment", child->name) == 0) || (xmlStrcmp ((const xmlChar *) "text", child->name) == 0)) @@ -439,7 +433,6 @@ static int ascent_xml (const char *data) /* {{{ */ { xmlDoc *doc; xmlNode *cur; - xmlNode *child; #if 0 doc = xmlParseMemory (data, strlen (data), @@ -470,7 +463,7 @@ static int ascent_xml (const char *data) /* {{{ */ return (-1); } - for (child = cur->xmlChildrenNode; child != NULL; child = child->next) + for (xmlNode *child = cur->xmlChildrenNode; child != NULL; child = child->next) { if ((xmlStrcmp ((const xmlChar *) "comment", child->name) == 0) || (xmlStrcmp ((const xmlChar *) "text", child->name) == 0)) diff --git a/src/barometer.c b/src/barometer.c index e1a45cd8..fba3450a 100644 --- a/src/barometer.c +++ b/src/barometer.c @@ -408,7 +408,6 @@ static int get_reference_temperature(double * result) gauge_t * values = NULL; /**< rate values */ size_t values_num = 0; /**< number of rate values */ - size_t i; gauge_t values_history[REF_TEMP_AVG_NUM]; @@ -446,7 +445,7 @@ static int get_reference_temperature(double * result) list->initialized = 1; list->num_values = values_num; - for(i=0; inum_values; ++i) + for(size_t i=0; inum_values; ++i) { DEBUG ("barometer: get_reference_temperature - history %zu: %lf", i, values_history[i]); @@ -500,7 +499,7 @@ static int get_reference_temperature(double * result) continue; } - for(i=0; ichildren_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/bind.c b/src/bind.c index c768b665..7fda0349 100644 --- a/src/bind.c +++ b/src/bind.c @@ -310,12 +310,11 @@ static int bind_xml_table_callback (const char *name, value_t value, /* {{{ */ time_t current_time, void *user_data) { translation_table_ptr_t *table = (translation_table_ptr_t *) user_data; - size_t i; if (table == NULL) return (-1); - for (i = 0; i < table->table_length; i++) + for (size_t i = 0; i < table->table_length; i++) { if (strcmp (table->table[i].xml_name, name) != 0) continue; @@ -491,7 +490,6 @@ static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ * { xmlXPathObject *xpathObj = NULL; int num_entries; - int i; xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx); if (xpathObj == NULL) @@ -503,19 +501,18 @@ static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ * num_entries = 0; /* Iterate over all matching nodes. */ - for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++) + for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++) { xmlNode *name_node = NULL; xmlNode *counter = NULL; xmlNode *parent; - xmlNode *child; parent = xpathObj->nodesetval->nodeTab[i]; DEBUG ("bind plugin: bind_parse_generic_name_value: parent->name = %s;", (char *) parent->name); /* Iterate over all child nodes. */ - for (child = parent->xmlChildrenNode; + for (xmlNode *child = parent->xmlChildrenNode; child != NULL; child = child->next) { @@ -578,7 +575,6 @@ static int bind_parse_generic_value_list (const char *xpath_expression, /* {{{ * { xmlXPathObject *xpathObj = NULL; int num_entries; - int i; xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx); if (xpathObj == NULL) @@ -590,12 +586,10 @@ static int bind_parse_generic_value_list (const char *xpath_expression, /* {{{ * num_entries = 0; /* Iterate over all matching nodes. */ - for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++) + for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++) { - xmlNode *child; - /* Iterate over all child nodes. */ - for (child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode; + for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode; child != NULL; child = child->next) { @@ -649,7 +643,6 @@ static int bind_parse_generic_name_attr_value_list (const char *xpath_expression { xmlXPathObject *xpathObj = NULL; int num_entries; - int i; xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx); if (xpathObj == NULL) @@ -661,12 +654,10 @@ static int bind_parse_generic_name_attr_value_list (const char *xpath_expression num_entries = 0; /* Iterate over all matching nodes. */ - for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++) + for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++) { - xmlNode *child; - /* Iterate over all child nodes. */ - for (child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode; + for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode; child != NULL; child = child->next) { @@ -714,7 +705,6 @@ static int bind_xml_stats_handle_zone (int version, xmlDoc *doc, /* {{{ */ { xmlXPathObject *path_obj; char *zone_name = NULL; - int i; size_t j; if (version >= 3) @@ -738,7 +728,7 @@ static int bind_xml_stats_handle_zone (int version, xmlDoc *doc, /* {{{ */ return (-1); } - for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++) + for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++) { zone_name = (char *) xmlNodeListGetString (doc, path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1); @@ -817,7 +807,6 @@ static int bind_xml_stats_search_zones (int version, xmlDoc *doc, /* {{{ */ { xmlXPathObject *zone_nodes = NULL; xmlXPathContext *zone_path_context; - int i; zone_path_context = xmlXPathNewContext (doc); if (zone_path_context == NULL) @@ -834,7 +823,7 @@ static int bind_xml_stats_search_zones (int version, xmlDoc *doc, /* {{{ */ return (-1); } - for (i = 0; i < zone_nodes->nodesetval->nodeNr; i++) + for (int i = 0; i < zone_nodes->nodesetval->nodeNr; i++) { node = zone_nodes->nodesetval->nodeTab[i]; assert (node != NULL); @@ -855,7 +844,6 @@ static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */ { char *view_name = NULL; cb_view_t *view; - int i; size_t j; if (version == 3) @@ -887,7 +875,7 @@ static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */ return (-1); } - for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++) + for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++) { view_name = (char *) xmlNodeListGetString (doc, path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1); @@ -1010,7 +998,6 @@ static int bind_xml_stats_search_views (int version, xmlDoc *doc, /* {{{ */ { xmlXPathObject *view_nodes = NULL; xmlXPathContext *view_path_context; - int i; view_path_context = xmlXPathNewContext (doc); if (view_path_context == NULL) @@ -1027,7 +1014,7 @@ static int bind_xml_stats_search_views (int version, xmlDoc *doc, /* {{{ */ return (-1); } - for (i = 0; i < view_nodes->nodesetval->nodeNr; i++) + for (int i = 0; i < view_nodes->nodesetval->nodeNr; i++) { xmlNode *node; @@ -1441,7 +1428,6 @@ static int bind_xml (const char *data) /* {{{ */ xmlXPathContext *xpathCtx = NULL; xmlXPathObject *xpathObj = NULL; int ret = -1; - int i; doc = xmlParseMemory (data, strlen (data)); if (doc == NULL) @@ -1471,7 +1457,7 @@ static int bind_xml (const char *data) /* {{{ */ } else { - for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) + for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) { xmlNode *node; char *attr_version; @@ -1533,7 +1519,7 @@ static int bind_xml (const char *data) /* {{{ */ return (-1); } - for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) + for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) { xmlNode *node; char *attr_version; @@ -1636,7 +1622,6 @@ static int bind_config_add_view_zone (cb_view_t *view, /* {{{ */ static int bind_config_add_view (oconfig_item_t *ci) /* {{{ */ { cb_view_t *tmp; - int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { @@ -1668,7 +1653,7 @@ static int bind_config_add_view (oconfig_item_t *ci) /* {{{ */ return (-1); } - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -1693,9 +1678,7 @@ static int bind_config_add_view (oconfig_item_t *ci) /* {{{ */ static int bind_config (oconfig_item_t *ci) /* {{{ */ { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/ceph.c b/src/ceph.c index 62f75816..cbfdd22c 100644 --- a/src/ceph.c +++ b/src/ceph.c @@ -270,14 +270,13 @@ ceph_cb_number(void *ctx, const char *number_val, yajl_len_t number_len) char buffer[number_len+1]; char key[2 * DATA_MAX_NAME_LEN]; _Bool latency_type = 0; - size_t i; int status; key[0] = '\0'; memcpy(buffer, number_val, number_len); buffer[sizeof(buffer) - 1] = '\0'; - for (i = 0; i < state->depth; i++) + for (size_t i = 0; i < state->depth; i++) { if (state->stack[i] == NULL) continue; @@ -423,8 +422,7 @@ static void ceph_daemon_print(const struct ceph_daemon *d) static void ceph_daemons_print(void) { - int i; - for(i = 0; i < g_num_daemons; ++i) + for(int i = 0; i < g_num_daemons; ++i) { ceph_daemon_print(g_daemons[i]); } @@ -432,15 +430,15 @@ static void ceph_daemons_print(void) static void ceph_daemon_free(struct ceph_daemon *d) { - int i = 0; - for(; i < d->last_idx; i++) + for(int i = 0; i < d->last_idx; i++) { sfree(d->last_poll_data[i]); } sfree(d->last_poll_data); d->last_poll_data = NULL; d->last_idx = 0; - for(i = 0; i < d->ds_num; i++) + + for(int i = 0; i < d->ds_num; i++) { sfree(d->ds_names[i]); } @@ -549,10 +547,9 @@ static _Bool has_suffix (char const *str, char const *suffix) /* count_parts returns the number of elements a "foo.bar.baz" style key has. */ static size_t count_parts (char const *key) { - char const *ptr; size_t parts_num = 0; - for (ptr = key; ptr != NULL; ptr = strchr (ptr + 1, '.')) + for (const char *ptr = key; ptr != NULL; ptr = strchr (ptr + 1, '.')) parts_num++; return parts_num; @@ -684,7 +681,7 @@ static int cc_handle_bool(struct oconfig_item_s *item, int *dest) static int cc_add_daemon_config(oconfig_item_t *ci) { - int ret, i; + int ret; struct ceph_daemon *nd, cd = { 0 }; struct ceph_daemon **tmp; @@ -701,7 +698,7 @@ static int cc_add_daemon_config(oconfig_item_t *ci) return ret; } - for(i=0; i < ci->children_num; i++) + for(int i=0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -758,9 +755,9 @@ static int cc_add_daemon_config(oconfig_item_t *ci) static int ceph_config(oconfig_item_t *ci) { - int ret, i; + int ret; - for(i = 0; i < ci->children_num; ++i) + for(int i = 0; i < ci->children_num; ++i) { oconfig_item_t *child = ci->children + i; if(strcasecmp("Daemon", child->key) == 0) @@ -897,8 +894,7 @@ static int update_last(struct ceph_daemon *d, const char *ds_n, int index, */ static int backup_search_for_last_avg(struct ceph_daemon *d, const char *ds_n) { - int i = 0; - for(; i < d->last_idx; i++) + for(int i = 0; i < d->last_idx; i++) { if(strcmp(d->last_poll_data[i]->ds_name, ds_n) == 0) { @@ -958,12 +954,11 @@ static double get_last_avg(struct ceph_daemon *d, const char *ds_n, int index, */ static uint32_t backup_search_for_type(struct ceph_daemon *d, char *ds_name) { - int idx = 0; - for(; idx < d->ds_num; idx++) + for(int i = 0; i < d->ds_num; i++) { - if(strcmp(d->ds_names[idx], ds_name) == 0) + if(strcmp(d->ds_names[i], ds_name) == 0) { - return d->ds_types[idx]; + return d->ds_types[i]; } } return DSET_TYPE_UNFOUND; @@ -1458,7 +1453,7 @@ static int milli_diff(const struct timeval *t1, const struct timeval *t2) */ static int cconn_main_loop(uint32_t request_type) { - int i, ret, some_unreachable = 0; + int ret, some_unreachable = 0; struct timeval end_tv; struct cconn io_array[g_num_daemons]; @@ -1466,7 +1461,7 @@ static int cconn_main_loop(uint32_t request_type) /* create cconn array */ memset(io_array, 0, sizeof(io_array)); - for(i = 0; i < g_num_daemons; ++i) + for(int i = 0; i < g_num_daemons; ++i) { io_array[i].d = g_daemons[i]; io_array[i].request_type = request_type; @@ -1485,7 +1480,7 @@ static int cconn_main_loop(uint32_t request_type) struct pollfd fds[g_num_daemons]; memset(fds, 0, sizeof(fds)); nfds = 0; - for(i = 0; i < g_num_daemons; ++i) + for(int i = 0; i < g_num_daemons; ++i) { struct cconn *io = io_array + i; ret = cconn_prepare(io, fds + nfds); @@ -1523,7 +1518,7 @@ static int cconn_main_loop(uint32_t request_type) ERROR("ceph plugin: poll(2) error: %d", ret); goto done; } - for(i = 0; i < nfds; ++i) + for(int i = 0; i < nfds; ++i) { struct cconn *io = polled_io_array[i]; int revents = fds[i].revents; @@ -1554,7 +1549,7 @@ static int cconn_main_loop(uint32_t request_type) } } } - done: for(i = 0; i < g_num_daemons; ++i) + done: for(int i = 0; i < g_num_daemons; ++i) { cconn_close(io_array + i); } @@ -1587,8 +1582,7 @@ static int ceph_init(void) static int ceph_shutdown(void) { - int i; - for(i = 0; i < g_num_daemons; ++i) + for(int i = 0; i < g_num_daemons; ++i) { ceph_daemon_free(g_daemons[i]); } diff --git a/src/cgroups.c b/src/cgroups.c index 508ba90f..3a59ec4c 100644 --- a/src/cgroups.c +++ b/src/cgroups.c @@ -207,18 +207,16 @@ static int cgroups_config (const char *key, const char *value) static int cgroups_read (void) { - cu_mount_t *mnt_list; - cu_mount_t *mnt_ptr; + cu_mount_t *mnt_list = NULL; _Bool cgroup_found = 0; - mnt_list = NULL; if (cu_mount_getlist (&mnt_list) == NULL) { ERROR ("cgroups plugin: cu_mount_getlist failed."); return (-1); } - for (mnt_ptr = mnt_list; mnt_ptr != NULL; mnt_ptr = mnt_ptr->next) + for (cu_mount_t *mnt_ptr = mnt_list; mnt_ptr != NULL; mnt_ptr = mnt_ptr->next) { /* Find the cgroup mountpoint which contains the cpuacct * controller. */ diff --git a/src/chrony.c b/src/chrony.c index 1735b495..0485036a 100644 --- a/src/chrony.c +++ b/src/chrony.c @@ -1053,7 +1053,7 @@ chrony_read(void) { /* collectd read callback: Perform data acquisition */ int rc; - unsigned int now_src, n_sources; + unsigned int n_sources; if (g_chrony_seq_is_initialized == 0) { @@ -1075,7 +1075,7 @@ chrony_read(void) if (rc != CHRONY_RC_OK) return rc; - for (now_src = 0; now_src < n_sources; ++now_src) + for (unsigned int now_src = 0; now_src < n_sources; ++now_src) { int is_reachable; rc = chrony_request_source_data(now_src, &is_reachable); diff --git a/src/collectd-nagios.c b/src/collectd-nagios.c index c1a85156..12187f30 100644 --- a/src/collectd-nagios.c +++ b/src/collectd-nagios.c @@ -128,8 +128,6 @@ static int filter_ds (size_t *values_num, gauge_t *new_values; char **new_names; - size_t i; - if (match_ds_g == NULL) return (RET_OKAY); @@ -148,7 +146,7 @@ static int filter_ds (size_t *values_num, return (RET_UNKNOWN); } - for (i = 0; i < match_ds_num_g; i++) + for (size_t i = 0; i < match_ds_num_g; i++) { size_t j; @@ -182,7 +180,7 @@ static int filter_ds (size_t *values_num, } free (*values); - for (i = 0; i < *values_num; i++) + for (size_t i = 0; i < *values_num; i++) free ((*values_names)[i]); free (*values_names); @@ -283,7 +281,6 @@ static int do_listval (lcc_connection_t *connection) char *hostname = NULL; int status; - size_t i; status = lcc_listval (connection, &ret_ident, &ret_ident_num); if (status != 0) { @@ -301,7 +298,7 @@ static int do_listval (lcc_connection_t *connection) return (RET_UNKNOWN); } - for (i = 0; i < ret_ident_num; ++i) { + for (size_t i = 0; i < ret_ident_num; ++i) { char id[1024]; if ((hostname_g != NULL) && (strcasecmp (hostname_g, ret_ident[i].host))) @@ -345,9 +342,8 @@ static int do_check_con_none (size_t values_num, int num_okay = 0; const char *status_str = "UNKNOWN"; int status_code = RET_UNKNOWN; - size_t i; - for (i = 0; i < values_num; i++) + for (size_t i = 0; i < values_num; i++) { if (isnan (values[i])) { @@ -390,7 +386,7 @@ static int do_check_con_none (size_t values_num, if (values_num > 0) { printf (" |"); - for (i = 0; i < values_num; i++) + for (size_t i = 0; i < values_num; i++) printf (" %s=%f;;;;", values_names[i], values[i]); } printf ("\n"); @@ -401,7 +397,6 @@ static int do_check_con_none (size_t values_num, static int do_check_con_average (size_t values_num, double *values, char **values_names) { - size_t i; double total; int total_num; double average; @@ -410,7 +405,7 @@ static int do_check_con_average (size_t values_num, total = 0.0; total_num = 0; - for (i = 0; i < values_num; i++) + for (size_t i = 0; i < values_num; i++) { if (isnan (values[i])) { @@ -451,7 +446,7 @@ static int do_check_con_average (size_t values_num, } printf ("%s: %g average |", status_str, average); - for (i = 0; i < values_num; i++) + for (size_t i = 0; i < values_num; i++) printf (" %s=%f;;;;", values_names[i], values[i]); printf ("\n"); @@ -461,7 +456,6 @@ static int do_check_con_average (size_t values_num, static int do_check_con_sum (size_t values_num, double *values, char **values_names) { - size_t i; double total; int total_num; const char *status_str = "UNKNOWN"; @@ -469,7 +463,7 @@ static int do_check_con_sum (size_t values_num, total = 0.0; total_num = 0; - for (i = 0; i < values_num; i++) + for (size_t i = 0; i < values_num; i++) { if (isnan (values[i])) { @@ -508,7 +502,7 @@ static int do_check_con_sum (size_t values_num, } printf ("%s: %g sum |", status_str, total); - for (i = 0; i < values_num; i++) + for (size_t i = 0; i < values_num; i++) printf (" %s=%f;;;;", values_names[i], values[i]); printf ("\n"); @@ -518,7 +512,6 @@ static int do_check_con_sum (size_t values_num, static int do_check_con_percentage (size_t values_num, double *values, char **values_names) { - size_t i; double sum = 0.0; double percentage; @@ -531,7 +524,7 @@ static int do_check_con_percentage (size_t values_num, return (RET_WARNING); } - for (i = 0; i < values_num; i++) + for (size_t i = 0; i < values_num; i++) { if (isnan (values[i])) { @@ -571,7 +564,7 @@ static int do_check_con_percentage (size_t values_num, } printf ("%s: %lf percent |", status_str, percentage); - for (i = 0; i < values_num; i++) + for (size_t i = 0; i < values_num; i++) printf (" %s=%lf;;;;", values_names[i], values[i]); return (status_code); } /* int do_check_con_percentage */ @@ -583,7 +576,6 @@ static int do_check (lcc_connection_t *connection) size_t values_num; char ident_str[1024]; lcc_identifier_t ident; - size_t i; int status; snprintf (ident_str, sizeof (ident_str), "%s/%s", @@ -627,7 +619,7 @@ static int do_check (lcc_connection_t *connection) free (values); if (values_names != NULL) - for (i = 0; i < values_num; i++) + for (size_t i = 0; i < values_num; i++) free (values_names[i]); free (values_names); diff --git a/src/collectd-tg.c b/src/collectd-tg.c index 513d4ffc..7db9fe71 100644 --- a/src/collectd-tg.c +++ b/src/collectd-tg.c @@ -337,7 +337,6 @@ static int read_options (int argc, char **argv) /* {{{ */ int main (int argc, char **argv) /* {{{ */ { - int i; double last_time; int values_sent = 0; @@ -383,7 +382,7 @@ int main (int argc, char **argv) /* {{{ */ fprintf (stdout, "Creating %i values ... ", conf_num_values); fflush (stdout); - for (i = 0; i < conf_num_values; i++) + for (int i = 0; i < conf_num_values; i++) { lcc_value_list_t *vl; diff --git a/src/collectdctl.c b/src/collectdctl.c index 8ca0559d..e60781a9 100644 --- a/src/collectdctl.c +++ b/src/collectdctl.c @@ -185,7 +185,6 @@ static int getval (lcc_connection_t *c, int argc, char **argv) char **ret_values_names = NULL; int status; - size_t i; assert (strcasecmp (argv[0], "getval") == 0); @@ -203,7 +202,7 @@ static int getval (lcc_connection_t *c, int argc, char **argv) if (ret_values != NULL) \ free (ret_values); \ if (ret_values_names != NULL) { \ - for (i = 0; i < ret_values_num; ++i) \ + for (size_t i = 0; i < ret_values_num; ++i) \ free (ret_values_names[i]); \ free (ret_values_names); \ } \ @@ -218,7 +217,7 @@ static int getval (lcc_connection_t *c, int argc, char **argv) BAIL_OUT (-1); } - for (i = 0; i < ret_values_num; ++i) + for (size_t i = 0; i < ret_values_num; ++i) printf ("%s=%e\n", ret_values_names[i], ret_values[i]); BAIL_OUT (0); #undef BAIL_OUT @@ -235,7 +234,6 @@ static int flush (lcc_connection_t *c, int argc, char **argv) size_t plugins_num = 0; int status; - int i; assert (strcasecmp (argv[0], "flush") == 0); @@ -250,7 +248,7 @@ static int flush (lcc_connection_t *c, int argc, char **argv) return (s); \ } while (0) - for (i = 1; i < argc; ++i) { + for (int i = 1; i < argc; ++i) { char *key, *value; key = argv[i]; @@ -314,7 +312,7 @@ static int flush (lcc_connection_t *c, int argc, char **argv) plugins[0] = NULL; } - for (i = 0; i < plugins_num; ++i) { + for (int i = 0; i < plugins_num; ++i) { if (identifiers_num == 0) { status = lcc_flush (c, plugins[i], NULL, timeout); if (status != 0) @@ -322,9 +320,7 @@ static int flush (lcc_connection_t *c, int argc, char **argv) (plugins[i] == NULL) ? "(all)" : plugins[i], lcc_strerror (c)); } else { - int j; - - for (j = 0; j < identifiers_num; ++j) { + for (int j = 0; j < identifiers_num; ++j) { status = lcc_flush (c, plugins[i], identifiers + j, timeout); if (status != 0) { char id[1024]; @@ -349,7 +345,6 @@ static int listval (lcc_connection_t *c, int argc, char **argv) size_t ret_ident_num = 0; int status; - size_t i; assert (strcasecmp (argv[0], "listval") == 0); @@ -372,7 +367,7 @@ static int listval (lcc_connection_t *c, int argc, char **argv) BAIL_OUT (status); } - for (i = 0; i < ret_ident_num; ++i) { + for (size_t i = 0; i < ret_ident_num; ++i) { char id[1024]; status = lcc_identifier_to_string (c, id, sizeof (id), ret_ident + i); @@ -398,7 +393,6 @@ static int putval (lcc_connection_t *c, int argc, char **argv) size_t values_len = 0; int status; - int i; assert (strcasecmp (argv[0], "putval") == 0); @@ -415,7 +409,7 @@ static int putval (lcc_connection_t *c, int argc, char **argv) if (status != 0) return (status); - for (i = 2; i < argc; ++i) { + for (int i = 2; i < argc; ++i) { char *tmp; tmp = strchr (argv[i], (int)'='); diff --git a/src/cpu.c b/src/cpu.c index f4bdbf99..80029667 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -406,19 +406,16 @@ static cpu_state_t *get_cpu_state (size_t cpu_num, size_t state) /* {{{ */ * array. */ static void aggregate (gauge_t *sum_by_state) /* {{{ */ { - size_t cpu_num; - size_t state; - - for (state = 0; state < COLLECTD_CPU_STATE_MAX; state++) + for (size_t state = 0; state < COLLECTD_CPU_STATE_MAX; state++) sum_by_state[state] = NAN; - for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++) + for (size_t cpu_num = 0; cpu_num < global_cpu_num; cpu_num++) { cpu_state_t *this_cpu_states = get_cpu_state (cpu_num, 0); this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].rate = NAN; - for (state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++) + for (size_t state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++) { if (!this_cpu_states[state].has_value) continue; @@ -443,7 +440,6 @@ static void aggregate (gauge_t *sum_by_state) /* {{{ */ static void cpu_commit_one (int cpu_num, /* {{{ */ gauge_t rates[static COLLECTD_CPU_STATE_MAX]) { - size_t state; gauge_t sum; sum = rates[COLLECTD_CPU_STATE_ACTIVE]; @@ -456,7 +452,7 @@ static void cpu_commit_one (int cpu_num, /* {{{ */ return; } - for (state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++) + for (size_t state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++) { gauge_t percent = 100.0 * rates[state] / sum; submit_percent (cpu_num, state, percent); @@ -467,9 +463,7 @@ static void cpu_commit_one (int cpu_num, /* {{{ */ * each iteration / after each call to cpu_commit(). */ static void cpu_reset (void) /* {{{ */ { - size_t i; - - for (i = 0; i < cpu_states_num; i++) + for (size_t i = 0; i < cpu_states_num; i++) cpu_states[i].has_value = 0; global_cpu_num = 0; @@ -478,13 +472,9 @@ static void cpu_reset (void) /* {{{ */ /* Legacy behavior: Dispatches the raw derive values without any aggregation. */ static void cpu_commit_without_aggregation (void) /* {{{ */ { - int state; - - for (state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++) + for (int state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++) { - size_t cpu_num; - - for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++) + for (size_t cpu_num = 0; cpu_num < global_cpu_num; cpu_num++) { cpu_state_t *s = get_cpu_state (cpu_num, state); @@ -502,7 +492,6 @@ static void cpu_commit (void) /* {{{ */ gauge_t global_rates[COLLECTD_CPU_STATE_MAX] = { NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN /* Batman! */ }; - size_t cpu_num; if (report_by_state && report_by_cpu && !report_percent) { @@ -518,15 +507,14 @@ static void cpu_commit (void) /* {{{ */ return; } - for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++) + for (size_t cpu_num = 0; cpu_num < global_cpu_num; cpu_num++) { cpu_state_t *this_cpu_states = get_cpu_state (cpu_num, 0); gauge_t local_rates[COLLECTD_CPU_STATE_MAX] = { NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN }; - size_t state; - for (state = 0; state < COLLECTD_CPU_STATE_MAX; state++) + for (size_t state = 0; state < COLLECTD_CPU_STATE_MAX; state++) if (this_cpu_states[state].has_value) local_rates[state] = this_cpu_states[state].rate; @@ -570,8 +558,6 @@ static int cpu_read (void) cdtime_t now = cdtime (); #if PROCESSOR_CPU_LOAD_INFO /* {{{ */ - int cpu; - kern_return_t status; processor_cpu_load_info_data_t cpu_info; @@ -579,7 +565,7 @@ static int cpu_read (void) host_t cpu_host; - for (cpu = 0; cpu < cpu_list_len; cpu++) + for (int cpu = 0; cpu < cpu_list_len; cpu++) { cpu_host = 0; cpu_info_len = PROCESSOR_BASIC_INFO_COUNT; @@ -654,13 +640,12 @@ static int cpu_read (void) /* }}} #endif defined(KERNEL_LINUX) */ #elif defined(HAVE_LIBKSTAT) /* {{{ */ - int cpu; static cpu_stat_t cs; if (kc == NULL) return (-1); - for (cpu = 0; cpu < numcpu; cpu++) + for (int cpu = 0; cpu < numcpu; cpu++) { if (kstat_read (kc, ksp[cpu], &cs) == -1) continue; /* error message? */ @@ -676,7 +661,6 @@ static int cpu_read (void) uint64_t cpuinfo[numcpu][CPUSTATES]; size_t cpuinfo_size; int status; - int i; if (numcpu < 1) { @@ -689,7 +673,7 @@ static int cpu_read (void) #if defined(KERN_CPTIME2) if (numcpu > 1) { - for (i = 0; i < numcpu; i++) { + for (int i = 0; i < numcpu; i++) { int mib[] = {CTL_KERN, KERN_CPTIME2, i}; cpuinfo_size = sizeof (cpuinfo[0]); @@ -722,12 +706,12 @@ static int cpu_read (void) return (-1); } - for(i = 0; i < CPUSTATES; i++) { + for(int i = 0; i < CPUSTATES; i++) { cpuinfo[0][i] = cpuinfo_tmp[i]; } } - for (i = 0; i < numcpu; i++) { + for (int i = 0; i < numcpu; i++) { cpu_stage (i, COLLECTD_CPU_STATE_USER, (derive_t) cpuinfo[i][CP_USER], now); cpu_stage (i, COLLECTD_CPU_STATE_NICE, (derive_t) cpuinfo[i][CP_NICE], now); cpu_stage (i, COLLECTD_CPU_STATE_SYSTEM, (derive_t) cpuinfo[i][CP_SYS], now); @@ -739,7 +723,6 @@ static int cpu_read (void) #elif defined(HAVE_SYSCTLBYNAME) && defined(HAVE_SYSCTL_KERN_CP_TIMES) /* {{{ */ long cpuinfo[maxcpu][CPUSTATES]; size_t cpuinfo_size; - int i; memset (cpuinfo, 0, sizeof (cpuinfo)); @@ -752,7 +735,7 @@ static int cpu_read (void) return (-1); } - for (i = 0; i < numcpu; i++) { + for (int i = 0; i < numcpu; i++) { cpu_stage (i, COLLECTD_CPU_STATE_USER, (derive_t) cpuinfo[i][CP_USER], now); cpu_stage (i, COLLECTD_CPU_STATE_NICE, (derive_t) cpuinfo[i][CP_NICE], now); cpu_stage (i, COLLECTD_CPU_STATE_SYSTEM, (derive_t) cpuinfo[i][CP_SYS], now); @@ -802,7 +785,7 @@ static int cpu_read (void) #elif defined(HAVE_PERFSTAT) /* {{{ */ perfstat_id_t id; - int i, cpus; + int cpus; numcpu = perfstat_cpu(NULL, NULL, sizeof(perfstat_cpu_t), 0); if(numcpu == -1) @@ -829,7 +812,7 @@ static int cpu_read (void) return (-1); } - for (i = 0; i < cpus; i++) + for (int i = 0; i < cpus; i++) { cpu_stage (i, COLLECTD_CPU_STATE_IDLE, (derive_t) perfcpu[i].idle, now); cpu_stage (i, COLLECTD_CPU_STATE_SYSTEM, (derive_t) perfcpu[i].sys, now); diff --git a/src/cpufreq.c b/src/cpufreq.c index 1550e777..1e9e8579 100644 --- a/src/cpufreq.c +++ b/src/cpufreq.c @@ -81,12 +81,11 @@ static int cpufreq_read (void) { int status; unsigned long long val; - int i = 0; FILE *fp; char filename[256]; char buffer[16]; - for (i = 0; i < num_cpu; i++) + for (int i = 0; i < num_cpu; i++) { status = ssnprintf (filename, sizeof (filename), "/sys/devices/system/cpu/cpu%d/cpufreq/" diff --git a/src/csv.c b/src/csv.c index f9db5957..e008ecfe 100644 --- a/src/csv.c +++ b/src/csv.c @@ -46,7 +46,6 @@ static int value_list_to_string (char *buffer, int buffer_len, { int offset; int status; - size_t i; gauge_t *rates = NULL; assert (0 == strcmp (ds->type, vl->type)); @@ -59,7 +58,7 @@ static int value_list_to_string (char *buffer, int buffer_len, return (-1); offset = status; - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { if ((ds->ds[i].type != DS_TYPE_COUNTER) && (ds->ds[i].type != DS_TYPE_GAUGE) @@ -188,7 +187,6 @@ static int value_list_to_filename (char *buffer, size_t buffer_size, static int csv_create_file (const char *filename, const data_set_t *ds) { FILE *csv; - size_t i; if (check_create_dir (filename)) return (-1); @@ -204,7 +202,7 @@ static int csv_create_file (const char *filename, const data_set_t *ds) } fprintf (csv, "epoch"); - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) fprintf (csv, ",%s", ds->ds[i].name); fprintf (csv, "\n"); @@ -289,12 +287,10 @@ static int csv_write (const data_set_t *ds, const value_list_t *vl, if (use_stdio) { - size_t i; - escape_string (filename, sizeof (filename)); /* Replace commas by colons for PUTVAL compatible output. */ - for (i = 0; i < sizeof (values); i++) + for (size_t i = 0; i < sizeof (values); i++) { if (values[i] == 0) break; diff --git a/src/curl.c b/src/curl.c index 0cfedf32..8d7baa51 100644 --- a/src/curl.c +++ b/src/curl.c @@ -270,7 +270,6 @@ static int cc_config_add_match (web_page_t *page, /* {{{ */ { web_match_t *match; int status; - int i; if (ci->values_num != 0) { @@ -285,7 +284,7 @@ static int cc_config_add_match (web_page_t *page, /* {{{ */ } status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -434,7 +433,6 @@ static int cc_config_add_page (oconfig_item_t *ci) /* {{{ */ { web_page_t *page; int status; - int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { @@ -469,7 +467,7 @@ static int cc_config_add_page (oconfig_item_t *ci) /* {{{ */ /* Process all children */ status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -567,12 +565,11 @@ static int cc_config (oconfig_item_t *ci) /* {{{ */ int success; int errors; int status; - int i; success = 0; errors = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -668,7 +665,6 @@ static void cc_submit_response_time (const web_page_t *wp, /* {{{ */ static int cc_read_page (web_page_t *wp) /* {{{ */ { - web_match_t *wm; int status; cdtime_t start = 0; @@ -701,7 +697,7 @@ static int cc_read_page (web_page_t *wp) /* {{{ */ } } - for (wm = wp->matches; wm != NULL; wm = wm->next) + for (web_match_t *wm = wp->matches; wm != NULL; wm = wm->next) { cu_match_value_t *mv; @@ -728,9 +724,7 @@ static int cc_read_page (web_page_t *wp) /* {{{ */ static int cc_read (void) /* {{{ */ { - web_page_t *wp; - - for (wp = pages_g; wp != NULL; wp = wp->next) + for (web_page_t *wp = pages_g; wp != NULL; wp = wp->next) cc_read_page (wp); return (0); diff --git a/src/curl_json.c b/src/curl_json.c index da989240..d4e78039 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -471,7 +471,6 @@ static int cj_config_add_key (cj_t *db, /* {{{ */ { cj_key_t *key; int status; - int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) @@ -507,7 +506,7 @@ static int cj_config_add_key (cj_t *db, /* {{{ */ } status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -663,7 +662,6 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */ { cj_t *db; int status = 0; - int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) @@ -700,7 +698,7 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */ } /* Fill the `cj_t' structure.. */ - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -796,12 +794,11 @@ static int cj_config (oconfig_item_t *ci) /* {{{ */ int success; int errors; int status; - int i; success = 0; errors = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -850,8 +847,8 @@ static void cj_submit (cj_t *db, cj_key_t *key, value_t *value) /* {{{ */ if (key->instance == NULL) { - int i, len = 0; - for (i = 0; i < db->depth; i++) + int len = 0; + for (int i = 0; i < db->depth; i++) len += ssnprintf(vl.type_instance+len, sizeof(vl.type_instance)-len, i ? "-%s" : "%s", db->state[i+1].name); } diff --git a/src/curl_xml.c b/src/curl_xml.c index 253356c0..f3aa2d9a 100644 --- a/src/curl_xml.c +++ b/src/curl_xml.c @@ -178,7 +178,6 @@ static void cx_list_free (llist_t *list) /* {{{ */ static void cx_free (void *arg) /* {{{ */ { cx_t *db; - size_t i; DEBUG ("curl_xml plugin: cx_free (arg = %p);", arg); @@ -207,7 +206,7 @@ static void cx_free (void *arg) /* {{{ */ curl_slist_free_all (db->headers); curl_stats_destroy (db->stats); - for (i = 0; i < db->namespaces_num; i++) + for (size_t i = 0; i < db->namespaces_num; i++) { sfree (db->namespaces[i].prefix); sfree (db->namespaces[i].url); @@ -369,14 +368,13 @@ static int cx_handle_all_value_xpaths (xmlXPathContextPtr xpath_ctx, /* {{{ */ { value_t values[xpath->values_len]; int status; - size_t i; assert (xpath->values_len > 0); assert (xpath->values_len == vl->values_len); assert (xpath->values_len == ds->ds_num); vl->values = values; - for (i = 0; i < xpath->values_len; i++) + for (size_t i = 0; i < xpath->values_len; i++) { status = cx_handle_single_value_xpath (xpath_ctx, xpath, ds, vl, i); if (status != 0) @@ -489,7 +487,6 @@ static int cx_handle_base_xpath (char const *plugin_instance, /* {{{ */ char *base_xpath, cx_xpath_t *xpath) { int total_nodes; - int i; xmlXPathObjectPtr base_node_obj = NULL; xmlNodeSetPtr base_nodes = NULL; @@ -530,7 +527,7 @@ static int cx_handle_base_xpath (char const *plugin_instance, /* {{{ */ if (plugin_instance != NULL) sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); - for (i = 0; i < total_nodes; i++) + for (int i = 0; i < total_nodes; i++) { int status; @@ -584,7 +581,6 @@ static int cx_parse_stats_xml(xmlChar* xml, cx_t *db) /* {{{ */ int status; xmlDocPtr doc; xmlXPathContextPtr xpath_ctx; - size_t i; /* Load the XML */ doc = xmlParseDoc(xml); @@ -602,7 +598,7 @@ static int cx_parse_stats_xml(xmlChar* xml, cx_t *db) /* {{{ */ return (-1); } - for (i = 0; i < db->namespaces_num; i++) + for (size_t i = 0; i < db->namespaces_num; i++) { cx_namespace_t const *ns = db->namespaces + i; status = xmlXPathRegisterNs (xpath_ctx, @@ -683,15 +679,13 @@ static int cx_read (user_data_t *ud) /* {{{ */ static int cx_config_add_values (const char *name, cx_xpath_t *xpath, /* {{{ */ oconfig_item_t *ci) { - int i; - if (ci->values_num < 1) { WARNING ("curl_xml plugin: `ValuesFrom' needs at least one argument."); return (-1); } - for (i = 0; i < ci->values_num; i++) + for (int i = 0; i < ci->values_num; i++) if (ci->values[i].type != OCONFIG_TYPE_STRING) { WARNING ("curl_xml plugin: `ValuesFrom' needs only string argument."); @@ -707,7 +701,7 @@ static int cx_config_add_values (const char *name, cx_xpath_t *xpath, /* {{{ */ xpath->values_len = (size_t) ci->values_num; /* populate cx_values_t structure */ - for (i = 0; i < ci->values_num; i++) + for (int i = 0; i < ci->values_num; i++) { xpath->values[i].path_len = sizeof (ci->values[i].value.string); sstrncpy (xpath->values[i].path, ci->values[i].value.string, sizeof (xpath->values[i].path)); @@ -722,7 +716,6 @@ static int cx_config_add_xpath (cx_t *db, oconfig_item_t *ci) /* {{{ */ char *name; llentry_t *le; int status; - int i; xpath = calloc (1, sizeof (*xpath)); if (xpath == NULL) @@ -748,7 +741,7 @@ static int cx_config_add_xpath (cx_t *db, oconfig_item_t *ci) /* {{{ */ } status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -927,7 +920,6 @@ static int cx_config_add_url (oconfig_item_t *ci) /* {{{ */ { cx_t *db; int status = 0; - int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) @@ -964,7 +956,7 @@ static int cx_config_add_url (oconfig_item_t *ci) /* {{{ */ } /* Fill the `cx_t' structure.. */ - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -1058,12 +1050,11 @@ static int cx_config (oconfig_item_t *ci) /* {{{ */ int success; int errors; int status; - int i; success = 0; errors = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/daemon/collectd.c b/src/daemon/collectd.c index b7377626..85735791 100644 --- a/src/daemon/collectd.c +++ b/src/daemon/collectd.c @@ -98,7 +98,6 @@ static int init_hostname (void) const char *str; struct addrinfo *ai_list; - struct addrinfo *ai_ptr; int status; str = global_option_get ("Hostname"); @@ -134,7 +133,7 @@ static int init_hostname (void) return (-1); } - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { if (ai_ptr->ai_canonname == NULL) continue; diff --git a/src/daemon/common.c b/src/daemon/common.c index ff2e5199..b60530a1 100644 --- a/src/daemon/common.c +++ b/src/daemon/common.c @@ -333,7 +333,6 @@ int strjoin (char *buffer, size_t buffer_size, size_t avail; char *ptr; size_t sep_len; - size_t i; if ((buffer_size < 1) || (fields_num == 0)) return (-1); @@ -346,7 +345,7 @@ int strjoin (char *buffer, size_t buffer_size, if (sep != NULL) sep_len = strlen (sep); - for (i = 0; i < fields_num; i++) + for (size_t i = 0; i < fields_num; i++) { size_t field_len; @@ -376,7 +375,6 @@ int strjoin (char *buffer, size_t buffer_size, int escape_string (char *buffer, size_t buffer_size) { char *temp; - size_t i; size_t j; /* Check if we need to escape at all first */ @@ -394,7 +392,7 @@ int escape_string (char *buffer, size_t buffer_size) temp[0] = '"'; j = 1; - for (i = 0; i < buffer_size; i++) + for (size_t i = 0; i < buffer_size; i++) { if (buffer[i] == 0) { @@ -428,9 +426,7 @@ int escape_string (char *buffer, size_t buffer_size) int strunescape (char *buf, size_t buf_len) { - size_t i; - - for (i = 0; (i < buf_len) && (buf[i] != '\0'); ++i) + for (size_t i = 0; (i < buf_len) && (buf[i] != '\0'); ++i) { if (buf[i] != '\\') continue; @@ -484,7 +480,6 @@ size_t strstripnewline (char *buffer) int escape_slashes (char *buffer, size_t buffer_size) { size_t buffer_len; - size_t i; buffer_len = strlen (buffer); @@ -506,7 +501,7 @@ int escape_slashes (char *buffer, size_t buffer_size) buffer_len--; } - for (i = 0; i < buffer_len; i++) + for (size_t i = 0; i < buffer_len; i++) { if (buffer[i] == '/') buffer[i] = '_'; @@ -517,9 +512,7 @@ int escape_slashes (char *buffer, size_t buffer_size) void replace_special (char *buffer, size_t buffer_size) { - size_t i; - - for (i = 0; i < buffer_size; i++) + for (size_t i = 0; i < buffer_size; i++) { if (buffer[i] == 0) return; @@ -593,7 +586,6 @@ int check_create_dir (const char *file_orig) int last_is_file = 1; int path_is_absolute = 0; size_t len; - int i; /* * Sanity checks first @@ -639,7 +631,7 @@ int check_create_dir (const char *file_orig) /* * For each component, do.. */ - for (i = 0; i < (fields_num - last_is_file); i++) + for (int i = 0; i < (fields_num - last_is_file); i++) { /* * Do not create directories that start with a dot. This @@ -938,7 +930,6 @@ int format_values (char *ret, size_t ret_len, /* {{{ */ { size_t offset = 0; int status; - size_t i; gauge_t *rates = NULL; assert (0 == strcmp (ds->type, vl->type)); @@ -964,7 +955,7 @@ int format_values (char *ret, size_t ret_len, /* {{{ */ BUFFER_ADD ("%.3f", CDTIME_T_TO_DOUBLE (vl->time)); - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { if (ds->ds[i].type == DS_TYPE_GAUGE) BUFFER_ADD (":"GAUGE_FORMAT, vl->values[i].gauge); @@ -1518,7 +1509,6 @@ int value_to_rate (gauge_t *ret_rate, /* {{{ */ int service_name_to_port_number (const char *service_name) { struct addrinfo *ai_list; - struct addrinfo *ai_ptr; int status; int service_number; @@ -1539,7 +1529,7 @@ int service_name_to_port_number (const char *service_name) } service_number = -1; - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { if (ai_ptr->ai_family == AF_INET) { @@ -1630,9 +1620,7 @@ int strarray_add (char ***ret_array, size_t *ret_array_len, char const *str) /* void strarray_free (char **array, size_t array_len) /* {{{ */ { - size_t i; - - for (i = 0; i < array_len; i++) + for (size_t i = 0; i < array_len; i++) sfree (array[i]); sfree (array); } /* }}} void strarray_free */ diff --git a/src/daemon/common_test.c b/src/daemon/common_test.c index 68958f3f..202ddf6c 100644 --- a/src/daemon/common_test.c +++ b/src/daemon/common_test.c @@ -203,9 +203,8 @@ DEF_TEST(escape_slashes) {"trailing/slash/", "trailing_slash_"}, {"foo//bar", "foo__bar"}, }; - size_t i; - for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) { + for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++) { char buffer[32]; strncpy (buffer, cases[i].str, sizeof (buffer)); @@ -230,9 +229,8 @@ DEF_TEST(escape_string) {"012345 78901234", "\"012345 789012\""}, {"012345 78901\"34", "\"012345 78901\""}, }; - size_t i; - for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) { + for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++) { char buffer[16]; strncpy (buffer, cases[i].str, sizeof (buffer)); @@ -301,8 +299,7 @@ DEF_TEST(parse_values) {"T:42.0", -1, NAN}, }; - size_t i; - for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) + for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++) { data_source_t dsrc = { .name = "value", @@ -361,9 +358,8 @@ DEF_TEST(value_to_rate) /* 64bit wrap-around. */ {30, 40, DS_TYPE_COUNTER, {.counter = 18446744073709551558ULL}, {.counter = 42}, 10.0}, }; - size_t i; - for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) { + for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++) { value_to_rate_state_t state = { cases[i].v0, TIME_T_TO_CDTIME_T (cases[i].t0) }; gauge_t got; diff --git a/src/daemon/configfile.c b/src/daemon/configfile.c index 0654ad7e..ff5e034e 100644 --- a/src/daemon/configfile.c +++ b/src/daemon/configfile.c @@ -155,7 +155,7 @@ static int cf_dispatch (const char *type, const char *orig_key, char *key; char *value; int ret; - int i; + int i = 0; if (orig_key == NULL) return (EINVAL); @@ -231,8 +231,6 @@ static int dispatch_global_option (const oconfig_item_t *ci) static int dispatch_value_typesdb (oconfig_item_t *ci) { - int i = 0; - assert (strcasecmp (ci->key, "TypesDB") == 0); cf_default_typesdb = 0; @@ -242,7 +240,7 @@ static int dispatch_value_typesdb (oconfig_item_t *ci) return (-1); } - for (i = 0; i < ci->values_num; ++i) + for (int i = 0; i < ci->values_num; ++i) { if (OCONFIG_TYPE_STRING != ci->values[i].type) { WARNING ("configfile: TypesDB: Skipping %i. argument which " @@ -270,7 +268,6 @@ static int dispatch_value_plugindir (oconfig_item_t *ci) static int dispatch_loadplugin (oconfig_item_t *ci) { - int i; const char *name; unsigned int flags = 0; plugin_ctx_t ctx = { 0 }; @@ -293,7 +290,7 @@ static int dispatch_loadplugin (oconfig_item_t *ci) ctx.flush_interval = 0; ctx.flush_timeout = 0; - for (i = 0; i < ci->children_num; ++i) + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *child = ci->children + i; @@ -325,12 +322,11 @@ static int dispatch_value_plugin (const char *plugin, oconfig_item_t *ci) char buffer[4096]; char *buffer_ptr; int buffer_free; - int i; buffer_ptr = buffer; buffer_free = sizeof (buffer); - for (i = 0; i < ci->values_num; i++) + for (int i = 0; i < ci->values_num; i++) { int status = -1; @@ -359,16 +355,15 @@ static int dispatch_value_plugin (const char *plugin, oconfig_item_t *ci) static int dispatch_value (oconfig_item_t *ci) { int ret = 0; - int i; - for (i = 0; i < cf_value_map_num; i++) + for (int i = 0; i < cf_value_map_num; i++) if (strcasecmp (cf_value_map[i].key, ci->key) == 0) { ret = cf_value_map[i].func (ci); break; } - for (i = 0; i < cf_global_options_num; i++) + for (int i = 0; i < cf_global_options_num; i++) if (strcasecmp (cf_global_options[i].key, ci->key) == 0) { ret = dispatch_global_option (ci); @@ -380,11 +375,8 @@ static int dispatch_value (oconfig_item_t *ci) static int dispatch_block_plugin (oconfig_item_t *ci) { - int i; const char *name; - cf_complex_callback_t *cb; - if (strcasecmp (ci->key, "Plugin") != 0) return (-1); if (ci->values_num < 1) @@ -426,7 +418,7 @@ static int dispatch_block_plugin (oconfig_item_t *ci) } /* Check for a complex callback first */ - for (cb = complex_callback_head; cb != NULL; cb = cb->next) + for (cf_complex_callback_t *cb = complex_callback_head; cb != NULL; cb = cb->next) { if (strcasecmp (name, cb->type) == 0) { @@ -441,7 +433,7 @@ static int dispatch_block_plugin (oconfig_item_t *ci) } /* Hm, no complex plugin found. Dispatch the values one by one */ - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { if (ci->children[i].children == NULL) dispatch_value_plugin (name, ci->children + i); @@ -477,7 +469,6 @@ static int cf_ci_replace_child (oconfig_item_t *dst, oconfig_item_t *src, int offset) { oconfig_item_t *temp; - int i; assert (offset >= 0); assert (dst->children_num > offset); @@ -485,7 +476,7 @@ static int cf_ci_replace_child (oconfig_item_t *dst, oconfig_item_t *src, /* Free the memory used by the replaced child. Usually that's the * `Include "blah"' statement. */ temp = dst->children + offset; - for (i = 0; i < temp->values_num; i++) + for (int i = 0; i < temp->values_num; i++) { if (temp->values[i].type == OCONFIG_TYPE_STRING) { @@ -586,17 +577,13 @@ static oconfig_item_t *cf_read_generic (const char *path, static int cf_include_all (oconfig_item_t *root, int depth) { - int i; - - for (i = 0; i < root->children_num; i++) + for (int i = 0; i < root->children_num; i++) { oconfig_item_t *new; oconfig_item_t *old; char *pattern = NULL; - int j; - if (strcasecmp (root->children[i].key, "Include") != 0) continue; @@ -609,7 +596,7 @@ static int cf_include_all (oconfig_item_t *root, int depth) continue; } - for (j = 0; j < old->children_num; ++j) + for (int j = 0; j < old->children_num; ++j) { oconfig_item_t *child = old->children + j; @@ -703,7 +690,6 @@ static oconfig_item_t *cf_read_dir (const char *dir, char **filenames = NULL; int filenames_num = 0; int status; - int i; assert (depth < CF_MAX_DEPTH); @@ -740,7 +726,7 @@ static oconfig_item_t *cf_read_dir (const char *dir, " name is too long.", dir, de->d_name); closedir (dh); - for (i = 0; i < filenames_num; ++i) + for (int i = 0; i < filenames_num; ++i) free (filenames[i]); free (filenames); free (root); @@ -753,7 +739,7 @@ static oconfig_item_t *cf_read_dir (const char *dir, if (tmp == NULL) { ERROR ("configfile: realloc failed."); closedir (dh); - for (i = 0; i < filenames_num - 1; ++i) + for (int i = 0; i < filenames_num - 1; ++i) free (filenames[i]); free (filenames); free (root); @@ -773,7 +759,7 @@ static oconfig_item_t *cf_read_dir (const char *dir, qsort ((void *) filenames, filenames_num, sizeof (*filenames), cf_compare_string); - for (i = 0; i < filenames_num; ++i) + for (int i = 0; i < filenames_num; ++i) { oconfig_item_t *temp; char *name = filenames[i]; @@ -817,7 +803,6 @@ static oconfig_item_t *cf_read_generic (const char *path, int status; const char *path_ptr; wordexp_t we; - size_t i; if (depth >= CF_MAX_DEPTH) { @@ -845,7 +830,7 @@ static oconfig_item_t *cf_read_generic (const char *path, qsort ((void *) we.we_wordv, we.we_wordc, sizeof (*we.we_wordv), cf_compare_string); - for (i = 0; i < we.we_wordc; i++) + for (size_t i = 0; i < we.we_wordc; i++) { oconfig_item_t *temp; struct stat statbuf; @@ -929,7 +914,6 @@ static oconfig_item_t *cf_read_generic (const char *path, int global_option_set (const char *option, const char *value, _Bool from_cli) { int i; - DEBUG ("option = %s; value = %s;", option, value); for (i = 0; i < cf_global_options_num; i++) @@ -965,7 +949,6 @@ int global_option_set (const char *option, const char *value, _Bool from_cli) const char *global_option_get (const char *option) { int i; - for (i = 0; i < cf_global_options_num; i++) if (strcasecmp (cf_global_options[i].key, option) == 0) break; @@ -1026,9 +1009,7 @@ cdtime_t cf_get_default_interval (void) void cf_unregister (const char *type) { - cf_callback_t *this, *prev; - - for (prev = NULL, this = first_callback; + for (cf_callback_t *prev = NULL, *this = first_callback; this != NULL; prev = this, this = this->next) if (strcasecmp (this->type, type) == 0) @@ -1045,9 +1026,7 @@ void cf_unregister (const char *type) void cf_unregister_complex (const char *type) { - cf_complex_callback_t *this, *prev; - - for (prev = NULL, this = complex_callback_head; + for (cf_complex_callback_t *prev = NULL, *this = complex_callback_head; this != NULL; prev = this, this = this->next) if (strcasecmp (this->type, type) == 0) @@ -1124,7 +1103,6 @@ int cf_register_complex (const char *type, int (*callback) (oconfig_item_t *)) int cf_read (const char *filename) { oconfig_item_t *conf; - int i; int ret = 0; conf = cf_read_generic (filename, /* pattern = */ NULL, /* depth = */ 0); @@ -1140,7 +1118,7 @@ int cf_read (const char *filename) return (-1); } - for (i = 0; i < conf->children_num; i++) + for (int i = 0; i < conf->children_num; i++) { if (conf->children[i].children == NULL) { diff --git a/src/daemon/filter_chain.c b/src/daemon/filter_chain.c index 5fb965f9..cee479a8 100644 --- a/src/daemon/filter_chain.c +++ b/src/daemon/filter_chain.c @@ -357,7 +357,6 @@ static int fc_config_add_rule (fc_chain_t *chain, /* {{{ */ fc_rule_t *rule; char rule_name[2*DATA_MAX_NAME_LEN] = "Unnamed rule"; int status = 0; - int i; if (ci->values_num > 1) { @@ -386,7 +385,7 @@ static int fc_config_add_rule (fc_chain_t *chain, /* {{{ */ ci->values[0].value.string); } - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; @@ -447,7 +446,6 @@ static int fc_config_add_chain (const oconfig_item_t *ci) /* {{{ */ { fc_chain_t *chain = NULL; int status = 0; - int i; int new_chain = 1; if ((ci->values_num != 1) @@ -475,7 +473,7 @@ static int fc_config_add_chain (const oconfig_item_t *ci) /* {{{ */ sstrncpy (chain->name, ci->values[0].value.string, sizeof (chain->name)); } - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; @@ -625,16 +623,13 @@ static int fc_bit_return_invoke (const data_set_t __attribute__((unused)) *ds, / static int fc_bit_write_create (const oconfig_item_t *ci, /* {{{ */ void **user_data) { - int i; - fc_writer_t *plugin_list = NULL; size_t plugin_list_len = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; fc_writer_t *temp; - int j; if (strcasecmp ("Plugin", child->key) != 0) { @@ -644,7 +639,7 @@ static int fc_bit_write_create (const oconfig_item_t *ci, /* {{{ */ continue; } - for (j = 0; j < child->values_num; j++) + for (int j = 0; j < child->values_num; j++) { char *plugin; @@ -685,14 +680,13 @@ static int fc_bit_write_create (const oconfig_item_t *ci, /* {{{ */ static int fc_bit_write_destroy (void **user_data) /* {{{ */ { fc_writer_t *plugin_list; - size_t i; if ((user_data == NULL) || (*user_data == NULL)) return (0); plugin_list = *user_data; - for (i = 0; plugin_list[i].plugin != NULL; i++) + for (size_t i = 0; plugin_list[i].plugin != NULL; i++) free (plugin_list[i].plugin); free (plugin_list); @@ -745,9 +739,7 @@ static int fc_bit_write_invoke (const data_set_t *ds, /* {{{ */ } else { - size_t i; - - for (i = 0; plugin_list[i].plugin != NULL; i++) + for (size_t i = 0; plugin_list[i].plugin != NULL; i++) { status = plugin_write (plugin_list[i].plugin, ds, vl); if (status != 0) @@ -875,12 +867,10 @@ int fc_register_target (const char *name, target_proc_t proc) /* {{{ */ fc_chain_t *fc_chain_get_by_name (const char *chain_name) /* {{{ */ { - fc_chain_t *chain; - if (chain_name == NULL) return (NULL); - for (chain = chain_list_head; chain != NULL; chain = chain->next) + for (fc_chain_t *chain = chain_list_head; chain != NULL; chain = chain->next) if (strcasecmp (chain_name, chain->name) == 0) return (chain); @@ -890,7 +880,6 @@ fc_chain_t *fc_chain_get_by_name (const char *chain_name) /* {{{ */ int fc_process_chain (const data_set_t *ds, value_list_t *vl, /* {{{ */ fc_chain_t *chain) { - fc_rule_t *rule; fc_target_t *target; int status = FC_TARGET_CONTINUE; @@ -899,7 +888,7 @@ int fc_process_chain (const data_set_t *ds, value_list_t *vl, /* {{{ */ DEBUG ("fc_process_chain (chain = %s);", chain->name); - for (rule = chain->rules; rule != NULL; rule = rule->next) + for (fc_rule_t *rule = chain->rules; rule != NULL; rule = rule->next) { fc_match_t *match; status = FC_TARGET_CONTINUE; diff --git a/src/daemon/meta_data.c b/src/daemon/meta_data.c index 73c6046d..9e4fd07e 100644 --- a/src/daemon/meta_data.c +++ b/src/daemon/meta_data.c @@ -333,8 +333,6 @@ meta_data_t *meta_data_clone (meta_data_t *orig) /* {{{ */ int meta_data_clone_merge (meta_data_t **dest, meta_data_t *orig) /* {{{ */ { - meta_entry_t *e; - if (orig == NULL) return (0); @@ -344,7 +342,7 @@ int meta_data_clone_merge (meta_data_t **dest, meta_data_t *orig) /* {{{ */ } pthread_mutex_lock (&orig->lock); - for (e=orig->head; e != NULL; e = e->next) + for (meta_entry_t *e=orig->head; e != NULL; e = e->next) { md_entry_insert_clone((*dest), e); } @@ -365,14 +363,12 @@ void meta_data_destroy (meta_data_t *md) /* {{{ */ int meta_data_exists (meta_data_t *md, const char *key) /* {{{ */ { - meta_entry_t *e; - if ((md == NULL) || (key == NULL)) return (-EINVAL); pthread_mutex_lock (&md->lock); - for (e = md->head; e != NULL; e = e->next) + for (meta_entry_t *e = md->head; e != NULL; e = e->next) { if (strcasecmp (key, e->key) == 0) { @@ -387,14 +383,12 @@ int meta_data_exists (meta_data_t *md, const char *key) /* {{{ */ int meta_data_type (meta_data_t *md, const char *key) /* {{{ */ { - meta_entry_t *e; - if ((md == NULL) || (key == NULL)) return -EINVAL; pthread_mutex_lock (&md->lock); - for (e = md->head; e != NULL; e = e->next) + for (meta_entry_t *e = md->head; e != NULL; e = e->next) { if (strcasecmp (key, e->key) == 0) { @@ -410,14 +404,13 @@ int meta_data_type (meta_data_t *md, const char *key) /* {{{ */ int meta_data_toc (meta_data_t *md, char ***toc) /* {{{ */ { int i = 0, count = 0; - meta_entry_t *e; if ((md == NULL) || (toc == NULL)) return -EINVAL; pthread_mutex_lock (&md->lock); - for (e = md->head; e != NULL; e = e->next) + for (meta_entry_t *e = md->head; e != NULL; e = e->next) ++count; if (count == 0) @@ -427,7 +420,7 @@ int meta_data_toc (meta_data_t *md, char ***toc) /* {{{ */ } *toc = calloc(count, sizeof(**toc)); - for (e = md->head; e != NULL; e = e->next) + for (meta_entry_t *e = md->head; e != NULL; e = e->next) (*toc)[i++] = strdup(e->key); pthread_mutex_unlock (&md->lock); diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index e0ad54c3..2ccc68c2 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -319,8 +319,8 @@ static void log_list_callbacks (llist_t **list, /* {{{ */ { char *str; int len; - llentry_t *le; int i; + llentry_t *le; int n; char **keys; @@ -655,8 +655,6 @@ static void *plugin_read_thread (void __attribute__((unused)) *args) static void start_read_threads (int num) { - int i; - if (read_threads != NULL) return; @@ -668,7 +666,7 @@ static void start_read_threads (int num) } read_threads_num = 0; - for (i = 0; i < num; i++) + for (int i = 0; i < num; i++) { if (pthread_create (read_threads + read_threads_num, NULL, plugin_read_thread, NULL) == 0) @@ -685,8 +683,6 @@ static void start_read_threads (int num) static void stop_read_threads (void) { - int i; - if (read_threads == NULL) return; @@ -698,7 +694,7 @@ static void stop_read_threads (void) pthread_cond_broadcast (&read_cond); pthread_mutex_unlock (&read_lock); - for (i = 0; i < read_threads_num; i++) + for (int i = 0; i < read_threads_num; i++) { if (pthread_join (read_threads[i], NULL) != 0) { @@ -870,8 +866,6 @@ static void *plugin_write_thread (void __attribute__((unused)) *args) /* {{{ */ static void start_write_threads (size_t num) /* {{{ */ { - size_t i; - if (write_threads != NULL) return; @@ -883,7 +877,7 @@ static void start_write_threads (size_t num) /* {{{ */ } write_threads_num = 0; - for (i = 0; i < num; i++) + for (size_t i = 0; i < num; i++) { int status; @@ -1460,7 +1454,6 @@ static void plugin_free_data_sets (void) int plugin_register_data_set (const data_set_t *ds) { data_set_t *ds_copy; - size_t i; if ((data_sets != NULL) && (c_avl_get (data_sets, ds->type, NULL) == 0)) @@ -1488,7 +1481,7 @@ int plugin_register_data_set (const data_set_t *ds) return (-1); } - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) memcpy (ds_copy->ds + i, ds->ds + i, sizeof (data_source_t)); return (c_avl_insert (data_sets, (void *) ds_copy->type, (void *) ds_copy)); @@ -2686,14 +2679,12 @@ int plugin_notification_meta_add_boolean (notification_t *n, int plugin_notification_meta_copy (notification_t *dst, const notification_t *src) { - notification_meta_t *meta; - assert (dst != NULL); assert (src != NULL); assert (dst != src); assert ((src->meta == NULL) || (src->meta != dst->meta)); - for (meta = src->meta; meta != NULL; meta = meta->next) + for (notification_meta_t *meta = src->meta; meta != NULL; meta = meta->next) { if (meta->type == NM_TYPE_STRING) plugin_notification_meta_add_string (dst, meta->name, diff --git a/src/daemon/types_list.c b/src/daemon/types_list.c index 436df674..34c222c7 100644 --- a/src/daemon/types_list.c +++ b/src/daemon/types_list.c @@ -103,7 +103,6 @@ static void parse_line (char *buf) char *fields[64]; size_t fields_num; data_set_t *ds; - size_t i; fields_num = strsplit (buf, fields, 64); if (fields_num < 2) @@ -127,7 +126,7 @@ static void parse_line (char *buf) return; } - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) if (parse_ds (ds->ds + i, fields[i + 1], strlen (fields[i + 1])) != 0) { ERROR ("types_list: parse_line: Cannot parse data source #%zu " diff --git a/src/daemon/utils_avltree_test.c b/src/daemon/utils_avltree_test.c index 2019ffa9..150dd1b5 100644 --- a/src/daemon/utils_avltree_test.c +++ b/src/daemon/utils_avltree_test.c @@ -71,13 +71,12 @@ DEF_TEST(success) }; c_avl_tree_t *t; - size_t i; RESET_COUNTS (); CHECK_NOT_NULL (t = c_avl_create (compare_callback)); /* insert */ - for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) + for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++) { char *key; char *value; @@ -90,11 +89,11 @@ DEF_TEST(success) } /* Key already exists. */ - for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) + for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++) EXPECT_EQ_INT (1, c_avl_insert (t, cases[i].key, cases[i].value)); /* get */ - for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) + for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++) { char *value_ret = NULL; @@ -103,7 +102,7 @@ DEF_TEST(success) } /* remove half */ - for (i = 0; i < STATIC_ARRAY_SIZE (cases) / 2; i++) + for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases) / 2; i++) { char *key = NULL; char *value = NULL; @@ -122,7 +121,7 @@ DEF_TEST(success) } /* pick the other half */ - for (i = STATIC_ARRAY_SIZE (cases) / 2; i < STATIC_ARRAY_SIZE (cases); i++) + for (size_t i = STATIC_ARRAY_SIZE (cases) / 2; i < STATIC_ARRAY_SIZE (cases); i++) { char *key = NULL; char *value = NULL; diff --git a/src/daemon/utils_cache.c b/src/daemon/utils_cache.c index 8dfe3599..7c1fa41e 100644 --- a/src/daemon/utils_cache.c +++ b/src/daemon/utils_cache.c @@ -136,9 +136,7 @@ static void cache_free (cache_entry_t *ce) static void uc_check_range (const data_set_t *ds, cache_entry_t *ce) { - size_t i; - - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { if (isnan (ce->values_gauge[i])) continue; @@ -154,7 +152,6 @@ static int uc_insert (const data_set_t *ds, const value_list_t *vl, { char *key_copy; cache_entry_t *ce; - size_t i; /* `cache_lock' has been locked by `uc_update' */ @@ -175,7 +172,7 @@ static int uc_insert (const data_set_t *ds, const value_list_t *vl, sstrncpy (ce->name, key, sizeof (ce->name)); - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { switch (ds->ds[i].type) { @@ -254,7 +251,6 @@ int uc_check_timeout (void) c_avl_iterator_t *iter; int status; - int i; pthread_mutex_lock (&cache_lock); @@ -326,7 +322,7 @@ int uc_check_timeout (void) * including plugin specific meta data, rates, history, …. This must be done * without holding the lock, otherwise we will run into a deadlock if a * plugin calls the cache interface. */ - for (i = 0; i < keys_len; i++) + for (int i = 0; i < keys_len; i++) { value_list_t vl = VALUE_LIST_INIT; @@ -351,7 +347,7 @@ int uc_check_timeout (void) * the timestamp again, so in theory it is possible we remove a value after * it is updated here. */ pthread_mutex_lock (&cache_lock); - for (i = 0; i < keys_len; i++) + for (int i = 0; i < keys_len; i++) { key = NULL; ce = NULL; @@ -383,7 +379,6 @@ int uc_update (const data_set_t *ds, const value_list_t *vl) char name[6 * DATA_MAX_NAME_LEN]; cache_entry_t *ce = NULL; int status; - size_t i; if (FORMAT_VL (name, sizeof (name), vl) != 0) { @@ -415,7 +410,7 @@ int uc_update (const data_set_t *ds, const value_list_t *vl) return (-1); } - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { switch (ds->ds[i].type) { @@ -464,7 +459,7 @@ int uc_update (const data_set_t *ds, const value_list_t *vl) if (ce->history != NULL) { assert (ce->history_index < ce->history_length); - for (i = 0; i < ce->values_num; i++) + for (size_t i = 0; i < ce->values_num; i++) { size_t hist_idx = (ce->values_num * ce->history_index) + i; ce->history[hist_idx] = ce->values_gauge[i]; @@ -644,9 +639,7 @@ int uc_get_names (char ***ret_names, cdtime_t **ret_times, size_t *ret_number) if (status != 0) { - size_t i; - - for (i = 0; i < number; i++) + for (size_t i = 0; i < number; i++) { sfree (names[i]); } @@ -721,7 +714,6 @@ int uc_get_history_by_name (const char *name, gauge_t *ret_history, size_t num_steps, size_t num_ds) { cache_entry_t *ce = NULL; - size_t i; int status = 0; pthread_mutex_lock (&cache_lock); @@ -753,7 +745,7 @@ int uc_get_history_by_name (const char *name, return (-ENOMEM); } - for (i = ce->history_length * ce->values_num; + for (size_t i = ce->history_length * ce->values_num; i < (num_steps * ce->values_num); i++) tmp[i] = NAN; @@ -763,7 +755,7 @@ int uc_get_history_by_name (const char *name, } /* if (ce->history_length < num_steps) */ /* Copy the values to the output buffer. */ - for (i = 0; i < num_steps; i++) + for (size_t i = 0; i < num_steps; i++) { size_t src_index; size_t dst_index; @@ -948,8 +940,6 @@ int uc_iterator_get_time (uc_iter_t *iter, cdtime_t *ret_time) int uc_iterator_get_values (uc_iter_t *iter, value_t **ret_values, size_t *ret_num) { - size_t i; - if ((iter == NULL) || (iter->entry == NULL) || (ret_values == NULL) || (ret_num == NULL)) return (-1); @@ -957,7 +947,7 @@ int uc_iterator_get_values (uc_iter_t *iter, value_t **ret_values, size_t *ret_n *ret_values = calloc (iter->entry->values_num, sizeof(*iter->entry->values_raw)); if (*ret_values == NULL) return (-1); - for (i = 0; i < iter->entry->values_num; ++i) + for (size_t i = 0; i < iter->entry->values_num; ++i) *ret_values[i] = iter->entry->values_raw[i]; *ret_num = iter->entry->values_num; diff --git a/src/daemon/utils_heap_test.c b/src/daemon/utils_heap_test.c index 82392ef8..54a9613a 100644 --- a/src/daemon/utils_heap_test.c +++ b/src/daemon/utils_heap_test.c @@ -45,14 +45,13 @@ static int compare (void const *v0, void const *v1) DEF_TEST(simple) { int values[] = { 9, 5, 6, 1, 3, 4, 0, 8, 2, 7 }; - int i; c_heap_t *h; CHECK_NOT_NULL(h = c_heap_create (compare)); - for (i = 0; i < 10; i++) + for (int i = 0; i < 10; i++) CHECK_ZERO(c_heap_insert (h, &values[i])); - for (i = 0; i < 5; i++) + for (int i = 0; i < 5; i++) { int *ret = NULL; CHECK_NOT_NULL(ret = c_heap_get_root(h)); @@ -65,7 +64,7 @@ DEF_TEST(simple) CHECK_ZERO(c_heap_insert (h, &values[4] /* = 3 */)); CHECK_ZERO(c_heap_insert (h, &values[5] /* = 4 */)); - for (i = 0; i < 10; i++) + for (int i = 0; i < 10; i++) { int *ret = NULL; CHECK_NOT_NULL(ret = c_heap_get_root(h)); diff --git a/src/daemon/utils_ignorelist.c b/src/daemon/utils_ignorelist.c index 311cb07b..ff73ad74 100644 --- a/src/daemon/utils_ignorelist.c +++ b/src/daemon/utils_ignorelist.c @@ -304,8 +304,6 @@ int ignorelist_add (ignorelist_t *il, const char *entry) */ int ignorelist_match (ignorelist_t *il, const char *entry) { - ignorelist_item_t *traverse; - /* if no entries, collect all */ if ((il == NULL) || (il->head == NULL)) return (0); @@ -314,7 +312,7 @@ int ignorelist_match (ignorelist_t *il, const char *entry) return (0); /* traverse list and check entries */ - for (traverse = il->head; traverse != NULL; traverse = traverse->next) + for (ignorelist_item_t *traverse = il->head; traverse != NULL; traverse = traverse->next) { #if HAVE_REGEX_H if (traverse->rmatch != NULL) diff --git a/src/daemon/utils_match.c b/src/daemon/utils_match.c index 803656d4..5273c901 100644 --- a/src/daemon/utils_match.c +++ b/src/daemon/utils_match.c @@ -324,7 +324,6 @@ int match_apply (cu_match_t *obj, const char *str) regmatch_t re_match[32]; char *matches[32] = { 0 }; size_t matches_num; - size_t i; if ((obj == NULL) || (str == NULL)) return (-1); @@ -376,7 +375,7 @@ int match_apply (cu_match_t *obj, const char *str) } } - for (i = 0; i < matches_num; i++) + for (size_t i = 0; i < matches_num; i++) { sfree (matches[i]); } diff --git a/src/daemon/utils_subst_test.c b/src/daemon/utils_subst_test.c index c180b7dc..c6caba20 100644 --- a/src/daemon/utils_subst_test.c +++ b/src/daemon/utils_subst_test.c @@ -76,9 +76,8 @@ DEF_TEST(subst) {"foo bar", 4, 3, "_", NULL}, /* off1 > off2 */ {"foo bar", 3, 4, NULL, NULL}, /* no replacement */ }; - size_t i; - for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) { + for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++) { char buffer[16] = "!!!!!!!!!!!!!!!"; if (cases[i].want == NULL) { @@ -109,9 +108,8 @@ DEF_TEST(subst_string) {"foo bar", "oo", "oo", "foo bar"}, {"sixteen chars", "chars", "characters", "sixteen charact"}, }; - size_t i; - for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) { + for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++) { char buffer[16]; if (cases[i].want == NULL) { diff --git a/src/daemon/utils_tail_match.c b/src/daemon/utils_tail_match.c index 604c6d4c..ffcaa90a 100644 --- a/src/daemon/utils_tail_match.c +++ b/src/daemon/utils_tail_match.c @@ -112,9 +112,8 @@ static int tail_callback (void *data, char *buf, int __attribute__((unused)) buflen) { cu_tail_match_t *obj = (cu_tail_match_t *) data; - size_t i; - for (i = 0; i < obj->matches_num; i++) + for (size_t i = 0; i < obj->matches_num; i++) match_apply (obj->matches[i].match, buf); return (0); @@ -143,8 +142,6 @@ cu_tail_match_t *tail_match_create (const char *filename) void tail_match_destroy (cu_tail_match_t *obj) { - size_t i; - if (obj == NULL) return; @@ -154,7 +151,7 @@ void tail_match_destroy (cu_tail_match_t *obj) obj->tail = NULL; } - for (i = 0; i < obj->matches_num; i++) + for (size_t i = 0; i < obj->matches_num; i++) { cu_tail_match_match_t *match = obj->matches + i; if (match->match != NULL) @@ -247,7 +244,6 @@ int tail_match_read (cu_tail_match_t *obj) { char buffer[4096]; int status; - size_t i; status = cu_tail_read (obj->tail, buffer, sizeof (buffer), tail_callback, (void *) obj); @@ -257,7 +253,7 @@ int tail_match_read (cu_tail_match_t *obj) return (status); } - for (i = 0; i < obj->matches_num; i++) + for (size_t i = 0; i < obj->matches_num; i++) { cu_tail_match_match_t *lt_match = obj->matches + i; diff --git a/src/daemon/utils_time_test.c b/src/daemon/utils_time_test.c index 493e591d..9f043683 100644 --- a/src/daemon/utils_time_test.c +++ b/src/daemon/utils_time_test.c @@ -65,9 +65,8 @@ DEF_TEST(conversion) // 1546167986577716567 / 2^30 = 1439981150.0475896215... {1546167986577716567ULL, 1439981150.048, 1439981150, 1439981150048ULL, {1439981150, 47590}, {1439981150, 47589622}}, }; - size_t i; - for (i = 0; i < (sizeof (cases) / sizeof (cases[0])); i++) { + for (size_t i = 0; i < (sizeof (cases) / sizeof (cases[0])); i++) { struct timeval tv; struct timespec ts; @@ -108,9 +107,8 @@ DEF_TEST(ns_to_cdtime) // 1439981880053705608 * 2^30 / 10^9 = 1546168770415815077.4 {1439981880053705608ULL, 1546168770415815077ULL}, }; - size_t i; - for (i = 0; i < (sizeof (cases) / sizeof (cases[0])); i++) { + for (size_t i = 0; i < (sizeof (cases) / sizeof (cases[0])); i++) { EXPECT_EQ_UINT64 (cases[i].want, NS_TO_CDTIME_T (cases[i].ns)); } diff --git a/src/dbi.c b/src/dbi.c index 78ac777f..b93aa51e 100644 --- a/src/dbi.c +++ b/src/dbi.c @@ -179,15 +179,13 @@ static int cdbi_result_get_field (dbi_result res, /* {{{ */ static void cdbi_database_free (cdbi_database_t *db) /* {{{ */ { - size_t i; - if (db == NULL) return; sfree (db->name); sfree (db->driver); - for (i = 0; i < db->driver_options_num; i++) + for (size_t i = 0; i < db->driver_options_num; i++) { sfree (db->driver_options[i].key); if (!db->driver_options[i].is_numeric) @@ -196,7 +194,7 @@ static void cdbi_database_free (cdbi_database_t *db) /* {{{ */ sfree (db->driver_options); if (db->q_prep_areas) - for (i = 0; i < db->queries_num; ++i) + for (size_t i = 0; i < db->queries_num; ++i) udb_query_delete_preparation_area (db->q_prep_areas[i]); free (db->q_prep_areas); @@ -285,7 +283,6 @@ static int cdbi_config_add_database (oconfig_item_t *ci) /* {{{ */ { cdbi_database_t *db; int status; - int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) @@ -310,7 +307,7 @@ static int cdbi_config_add_database (oconfig_item_t *ci) /* {{{ */ } /* Fill the `cdbi_database_t' structure.. */ - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -356,8 +353,6 @@ static int cdbi_config_add_database (oconfig_item_t *ci) /* {{{ */ while ((status == 0) && (db->queries_num > 0)) { - size_t j; - db->q_prep_areas = calloc (db->queries_num, sizeof (*db->q_prep_areas)); if (db->q_prep_areas == NULL) { @@ -366,12 +361,12 @@ static int cdbi_config_add_database (oconfig_item_t *ci) /* {{{ */ break; } - for (j = 0; j < db->queries_num; ++j) + for (size_t i = 0; i < db->queries_num; ++i) { - db->q_prep_areas[j] - = udb_query_allocate_preparation_area (db->queries[j]); + db->q_prep_areas[i] + = udb_query_allocate_preparation_area (db->queries[i]); - if (db->q_prep_areas[j] == NULL) + if (db->q_prep_areas[i] == NULL) { WARNING ("dbi plugin: udb_query_allocate_preparation_area failed"); status = -1; @@ -427,9 +422,7 @@ static int cdbi_config_add_database (oconfig_item_t *ci) /* {{{ */ static int cdbi_config (oconfig_item_t *ci) /* {{{ */ { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Query", child->key) == 0) @@ -498,7 +491,6 @@ static int cdbi_read_database_query (cdbi_database_t *db, /* {{{ */ char **column_names; char **column_values; int status; - size_t i; /* Macro that cleans up dynamically allocated memory and returns the * specified status. */ @@ -558,7 +550,7 @@ static int cdbi_read_database_query (cdbi_database_t *db, /* {{{ */ ERROR ("dbi plugin: calloc failed."); BAIL_OUT (-1); } - for (i = 1; i < column_num; i++) + for (size_t i = 1; i < column_num; i++) column_names[i] = column_names[i - 1] + DATA_MAX_NAME_LEN; column_values = calloc (column_num, sizeof (*column_values)); @@ -574,12 +566,12 @@ static int cdbi_read_database_query (cdbi_database_t *db, /* {{{ */ ERROR ("dbi plugin: calloc failed."); BAIL_OUT (-1); } - for (i = 1; i < column_num; i++) + for (size_t i = 1; i < column_num; i++) column_values[i] = column_values[i - 1] + DATA_MAX_NAME_LEN; /* }}} */ /* Copy the field names to `column_names' */ - for (i = 0; i < column_num; i++) /* {{{ */ + for (size_t i = 0; i < column_num; i++) /* {{{ */ { const char *column_name; @@ -619,7 +611,7 @@ static int cdbi_read_database_query (cdbi_database_t *db, /* {{{ */ { status = 0; /* Copy the value of the columns to `column_values' */ - for (i = 0; i < column_num; i++) /* {{{ */ + for (size_t i = 0; i < column_num; i++) /* {{{ */ { status = cdbi_result_get_field (res, (unsigned int) (i + 1), column_values[i], DATA_MAX_NAME_LEN); @@ -675,7 +667,6 @@ static int cdbi_connect_database (cdbi_database_t *db) /* {{{ */ { dbi_driver driver; dbi_conn connection; - size_t i; int status; if (db->connection != NULL) @@ -717,7 +708,7 @@ static int cdbi_connect_database (cdbi_database_t *db) /* {{{ */ * encountered, it will get a list of options understood by the driver and * report that as `INFO'. This way, users hopefully don't have too much * trouble finding out how to configure the plugin correctly.. */ - for (i = 0; i < db->driver_options_num; i++) + for (size_t i = 0; i < db->driver_options_num; i++) { if (db->driver_options[i].is_numeric) { @@ -750,11 +741,9 @@ static int cdbi_connect_database (cdbi_database_t *db) /* {{{ */ if (status != 0) { - char const *opt; - INFO ("dbi plugin: This is a list of all options understood " "by the `%s' driver:", db->driver); - for (opt = dbi_conn_get_option_list (connection, NULL); + for (const char *opt = dbi_conn_get_option_list (connection, NULL); opt != NULL; opt = dbi_conn_get_option_list (connection, opt)) { @@ -799,7 +788,6 @@ static int cdbi_connect_database (cdbi_database_t *db) /* {{{ */ static int cdbi_read_database (user_data_t *ud) /* {{{ */ { cdbi_database_t *db = (cdbi_database_t *) ud->data; - size_t i; int success; int status; @@ -814,7 +802,7 @@ static int cdbi_read_database (user_data_t *ud) /* {{{ */ /* TODO: Complain if `db_version == 0' */ success = 0; - for (i = 0; i < db->queries_num; i++) + for (size_t i = 0; i < db->queries_num; i++) { /* Check if we know the database's version and if so, if this query applies * to that version. */ @@ -839,9 +827,7 @@ static int cdbi_read_database (user_data_t *ud) /* {{{ */ static int cdbi_shutdown (void) /* {{{ */ { - size_t i; - - for (i = 0; i < databases_num; i++) + for (size_t i = 0; i < databases_num; i++) { if (databases[i]->connection != NULL) { diff --git a/src/df.c b/src/df.c index 1e360099..83be1764 100644 --- a/src/df.c +++ b/src/df.c @@ -191,7 +191,6 @@ static int df_read (void) #endif /* struct STATANYFS statbuf; */ cu_mount_t *mnt_list; - cu_mount_t *mnt_ptr; mnt_list = NULL; if (cu_mount_getlist (&mnt_list) == NULL) @@ -200,7 +199,7 @@ static int df_read (void) return (-1); } - for (mnt_ptr = mnt_list; mnt_ptr != NULL; mnt_ptr = mnt_ptr->next) + for (cu_mount_t *mnt_ptr = mnt_list; mnt_ptr != NULL; mnt_ptr = mnt_ptr->next) { unsigned long long blocksize; char disk_name[256]; @@ -274,12 +273,12 @@ static int df_read (void) sstrncpy (disk_name, "root", sizeof (disk_name)); else { - int i, len; + int len; sstrncpy (disk_name, mnt_ptr->dir + 1, sizeof (disk_name)); len = strlen (disk_name); - for (i = 0; i < len; i++) + for (int i = 0; i < len; i++) if (disk_name[i] == '/') disk_name[i] = '-'; } diff --git a/src/disk.c b/src/disk.c index a798a894..d7eb0a5c 100644 --- a/src/disk.c +++ b/src/disk.c @@ -954,12 +954,11 @@ static int disk_read (void) # error "kstat_io_t does not have the required members" # endif static kstat_io_t kio; - int i; if (kc == NULL) return (-1); - for (i = 0; i < numdisk; i++) + for (int i = 0; i < numdisk; i++) { if (kstat_read (kc, ksp[i], &kio) == -1) continue; @@ -997,13 +996,12 @@ static int disk_read (void) # else int disks; #endif - int counter; char name[DATA_MAX_NAME_LEN]; if ((ds = sg_get_disk_io_stats(&disks)) == NULL) return (0); - for (counter=0; counter < disks; counter++) { + for (int counter = 0; counter < disks; counter++) { strncpy(name, ds->disk_name, sizeof(name)); name[sizeof(name)-1] = '\0'; /* strncpy doesn't terminate longer strings */ @@ -1026,7 +1024,6 @@ static int disk_read (void) derive_t write_ops; perfstat_id_t firstpath; int rnumdisk; - int i; if ((numdisk = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0)) < 0) { @@ -1052,7 +1049,7 @@ static int disk_read (void) return (-1); } - for (i = 0; i < rnumdisk; i++) + for (int i = 0; i < rnumdisk; i++) { if (ignorelist_match (ignorelist, stat_disk[i].name) != 0) continue; diff --git a/src/dns.c b/src/dns.c index 17f87967..15fa15a7 100644 --- a/src/dns.c +++ b/src/dns.c @@ -390,7 +390,6 @@ static int dns_read (void) unsigned int keys[T_MAX]; unsigned int values[T_MAX]; int len; - int i; counter_list_t *ptr; @@ -412,7 +411,7 @@ static int dns_read (void) } pthread_mutex_unlock (&qtype_mutex); - for (i = 0; i < len; i++) + for (int i = 0; i < len; i++) { DEBUG ("dns plugin: qtype = %u; counter = %u;", keys[i], values[i]); submit_derive ("dns_qtype", qtype_str (keys[i]), values[i]); @@ -428,7 +427,7 @@ static int dns_read (void) } pthread_mutex_unlock (&opcode_mutex); - for (i = 0; i < len; i++) + for (int i = 0; i < len; i++) { DEBUG ("dns plugin: opcode = %u; counter = %u;", keys[i], values[i]); submit_derive ("dns_opcode", opcode_str (keys[i]), values[i]); @@ -444,7 +443,7 @@ static int dns_read (void) } pthread_mutex_unlock (&rcode_mutex); - for (i = 0; i < len; i++) + for (int i = 0; i < len; i++) { DEBUG ("dns plugin: rcode = %u; counter = %u;", keys[i], values[i]); submit_derive ("dns_rcode", rcode_str (keys[i]), values[i]); diff --git a/src/drbd.c b/src/drbd.c index 3485c0bb..70f03cab 100644 --- a/src/drbd.c +++ b/src/drbd.c @@ -70,7 +70,6 @@ static int drbd_submit_fields (long int resource, char plugin_instance[DATA_MAX_NAME_LEN]; value_t values[fields_num]; value_list_t vl = VALUE_LIST_INIT; - size_t i; if (resource < 0) { @@ -89,7 +88,7 @@ static int drbd_submit_fields (long int resource, ssnprintf (plugin_instance, sizeof (plugin_instance), "r%ld", resource); - for (i = 0; i < drbd_names_num; i++) + for (size_t i = 0; i < drbd_names_num; i++) { char *data; /* skip non numeric wo */ @@ -108,7 +107,7 @@ static int drbd_submit_fields (long int resource, sizeof (vl.plugin_instance)); sstrncpy (vl.type, "drbd_resource", sizeof (vl.type)); - for (i = 0; i < fields_num; i++) + for (size_t i = 0; i < fields_num; i++) { if (drbd_names[i] == NULL) continue; diff --git a/src/email.c b/src/email.c index 59f6beb0..9dce34c4 100644 --- a/src/email.c +++ b/src/email.c @@ -465,8 +465,6 @@ static void *open_connection (void __attribute__((unused)) *arg) } { /* initialize collector threads */ - int i = 0; - pthread_attr_t ptattr; conns.head = NULL; @@ -480,7 +478,7 @@ static void *open_connection (void __attribute__((unused)) *arg) collectors = smalloc (max_conns * sizeof (*collectors)); - for (i = 0; i < max_conns; ++i) { + for (int i = 0; i < max_conns; ++i) { collectors[i] = smalloc (sizeof (*collectors[i])); collectors[i]->socket = NULL; @@ -604,8 +602,6 @@ static void type_list_free (type_list_t *t) static int email_shutdown (void) { - int i = 0; - if (connector != ((pthread_t) 0)) { pthread_kill (connector, SIGTERM); connector = (pthread_t) 0; @@ -622,7 +618,7 @@ static int email_shutdown (void) available_collectors = 0; if (collectors != NULL) { - for (i = 0; i < max_conns; ++i) { + for (int i = 0; i < max_conns; ++i) { if (collectors[i] == NULL) continue; @@ -680,12 +676,9 @@ static void email_submit (const char *type, const char *type_instance, gauge_t v * after they have been copied to l2. */ static void copy_type_list (type_list_t *l1, type_list_t *l2) { - type_t *ptr1; - type_t *ptr2; - type_t *last = NULL; - for (ptr1 = l1->head, ptr2 = l2->head; NULL != ptr1; + for (type_t *ptr1 = l1->head, *ptr2 = l2->head; NULL != ptr1; ptr1 = ptr1->next, last = ptr2, ptr2 = ptr2->next) { if (NULL == ptr2) { ptr2 = smalloc (sizeof (*ptr2)); @@ -714,8 +707,6 @@ static void copy_type_list (type_list_t *l1, type_list_t *l2) static int email_read (void) { - type_t *ptr; - double score_old; int score_count_old; @@ -729,7 +720,7 @@ static int email_read (void) pthread_mutex_unlock (&count_mutex); - for (ptr = list_count_copy.head; NULL != ptr; ptr = ptr->next) { + for (type_t *ptr = list_count_copy.head; NULL != ptr; ptr = ptr->next) { email_submit ("email_count", ptr->name, ptr->value); } @@ -740,7 +731,7 @@ static int email_read (void) pthread_mutex_unlock (&size_mutex); - for (ptr = list_size_copy.head; NULL != ptr; ptr = ptr->next) { + for (type_t *ptr = list_size_copy.head; NULL != ptr; ptr = ptr->next) { email_submit ("email_size", ptr->name, ptr->value); } @@ -764,7 +755,7 @@ static int email_read (void) pthread_mutex_unlock (&check_mutex); - for (ptr = list_check_copy.head; NULL != ptr; ptr = ptr->next) + for (type_t *ptr = list_check_copy.head; NULL != ptr; ptr = ptr->next) email_submit ("spam_check", ptr->name, ptr->value); return (0); diff --git a/src/ethstat.c b/src/ethstat.c index 39af1407..a213b60a 100644 --- a/src/ethstat.c +++ b/src/ethstat.c @@ -150,9 +150,7 @@ static int ethstat_add_map (const oconfig_item_t *ci) /* {{{ */ static int ethstat_config (oconfig_item_t *ci) /* {{{ */ { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -222,7 +220,6 @@ static int ethstat_read_interface (char *device) size_t n_stats; size_t strings_size; size_t stats_size; - size_t i; int status; fd = socket(AF_INET, SOCK_DGRAM, /* protocol = */ 0); @@ -312,7 +309,7 @@ static int ethstat_read_interface (char *device) return (-1); } - for (i = 0; i < n_stats; i++) + for (size_t i = 0; i < n_stats; i++) { char *stat_name; @@ -336,9 +333,7 @@ static int ethstat_read_interface (char *device) static int ethstat_read(void) { - size_t i; - - for (i = 0; i < interfaces_num; i++) + for (size_t i = 0; i < interfaces_num; i++) ethstat_read_interface (interfaces[i]); return 0; diff --git a/src/exec.c b/src/exec.c index 699041a3..e90f83c9 100644 --- a/src/exec.c +++ b/src/exec.c @@ -246,9 +246,7 @@ static int exec_config_exec (oconfig_item_t *ci) /* {{{ */ static int exec_config (oconfig_item_t *ci) /* {{{ */ { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if ((strcasecmp ("Exec", child->key) == 0) @@ -471,11 +469,10 @@ static int fork_child (program_list_t *pl, int *fd_in, int *fd_out, int *fd_err) else if (pid == 0) { int fd_num; - int fd; /* Close all file descriptors but the pipe end we need. */ fd_num = getdtablesize (); - for (fd = 0; fd < fd_num; fd++) + for (int fd = 0; fd < fd_num; fd++) { if ((fd == fd_pipe_in[0]) || (fd == fd_pipe_out[1]) @@ -721,7 +718,6 @@ static void *exec_notification_one (void *arg) /* {{{ */ { program_list_t *pl = ((program_list_and_notification_t *) arg)->pl; notification_t *n = &((program_list_and_notification_t *) arg)->n; - notification_meta_t *meta; int fd; FILE *fh; int pid; @@ -769,7 +765,7 @@ static void *exec_notification_one (void *arg) /* {{{ */ if (strlen (n->type_instance) > 0) fprintf (fh, "TypeInstance: %s\n", n->type_instance); - for (meta = n->meta; meta != NULL; meta = meta->next) + for (notification_meta_t *meta = n->meta; meta != NULL; meta = meta->next) { if (meta->type == NM_TYPE_STRING) fprintf (fh, "%s: %s\n", meta->name, meta->nm_value.nm_string); @@ -815,9 +811,7 @@ static int exec_init (void) /* {{{ */ static int exec_read (void) /* {{{ */ { - program_list_t *pl; - - for (pl = pl_head; pl != NULL; pl = pl->next) + for (program_list_t *pl = pl_head; pl != NULL; pl = pl->next) { pthread_t t; pthread_attr_t attr; @@ -848,10 +842,9 @@ static int exec_read (void) /* {{{ */ static int exec_notification (const notification_t *n, /* {{{ */ user_data_t __attribute__((unused)) *user_data) { - program_list_t *pl; program_list_and_notification_t *pln; - for (pl = pl_head; pl != NULL; pl = pl->next) + for (program_list_t *pl = pl_head; pl != NULL; pl = pl->next) { pthread_t t; pthread_attr_t attr; diff --git a/src/filecount.c b/src/filecount.c index 169e9d0e..9de9e6c5 100644 --- a/src/filecount.c +++ b/src/filecount.c @@ -335,7 +335,6 @@ static int fc_config_add_dir (oconfig_item_t *ci) { fc_directory_conf_t *dir; int status; - int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { @@ -369,7 +368,7 @@ static int fc_config_add_dir (oconfig_item_t *ci) dir->size = 0; status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; @@ -429,9 +428,7 @@ static int fc_config_add_dir (oconfig_item_t *ci) static int fc_config (oconfig_item_t *ci) { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Directory", child->key) == 0) @@ -558,9 +555,7 @@ static int fc_read_dir (fc_directory_conf_t *dir) static int fc_read (void) { - size_t i; - - for (i = 0; i < directories_num; i++) + for (size_t i = 0; i < directories_num; i++) fc_read_dir (directories[i]); return (0); diff --git a/src/fscache.c b/src/fscache.c index 332a32c4..33633d63 100644 --- a/src/fscache.c +++ b/src/fscache.c @@ -159,7 +159,6 @@ static void fscache_read_stats_file (FILE *fh) char *lineptr; char *fields[32]; int fields_num; - int i; /* Find the colon and replace it with a null byte */ lineptr = strchr (linebuffer, ':'); @@ -183,7 +182,7 @@ static void fscache_read_stats_file (FILE *fh) if (fields_num <= 0) continue; - for (i = 0; i < fields_num; i++) + for (int i = 0; i < fields_num; i++) { char *field_name; char *field_value_str; diff --git a/src/gmond.c b/src/gmond.c index 5af0f329..2b299ca0 100644 --- a/src/gmond.c +++ b/src/gmond.c @@ -213,7 +213,6 @@ static int create_sockets (socket_entry_t **ret_sockets, /* {{{ */ const char *node, const char *service, int listen) { struct addrinfo *ai_list; - struct addrinfo *ai_ptr; int ai_return; socket_entry_t *sockets = NULL; @@ -244,7 +243,7 @@ static int create_sockets (socket_entry_t **ret_sockets, /* {{{ */ return (-1); } - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) /* {{{ */ + for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) /* {{{ */ { socket_entry_t *tmp; @@ -398,7 +397,6 @@ static int request_meta_data (const char *host, const char *name) /* {{{ */ char buffer[BUFF_SIZE] = { 0 }; unsigned int buffer_size; XDR xdr; - size_t i; msg.id = gmetadata_request; msg.Ganglia_metadata_msg_u.grequest.metric_id.host = strdup (host); @@ -427,7 +425,7 @@ static int request_meta_data (const char *host, const char *name) /* {{{ */ host, name); pthread_mutex_lock (&mc_send_sockets_lock); - for (i = 0; i < mc_send_sockets_num; i++) + for (size_t i = 0; i < mc_send_sockets_num; i++) { ssize_t status = sendto (mc_send_sockets[i].fd, buffer, (size_t) buffer_size, /* flags = */ 0, @@ -829,7 +827,6 @@ static void *mc_receive_thread (void *arg) /* {{{ */ { socket_entry_t *mc_receive_socket_entries; int status; - size_t i; mc_receive_socket_entries = NULL; status = create_sockets (&mc_receive_socket_entries, &mc_receive_sockets_num, @@ -847,7 +844,7 @@ static void *mc_receive_thread (void *arg) /* {{{ */ if (mc_receive_sockets == NULL) { ERROR ("gmond plugin: calloc failed."); - for (i = 0; i < mc_receive_sockets_num; i++) + for (size_t i = 0; i < mc_receive_sockets_num; i++) close (mc_receive_socket_entries[i].fd); free (mc_receive_socket_entries); mc_receive_socket_entries = NULL; @@ -855,7 +852,7 @@ static void *mc_receive_thread (void *arg) /* {{{ */ return ((void *) -1); } - for (i = 0; i < mc_receive_sockets_num; i++) + for (size_t i = 0; i < mc_receive_sockets_num; i++) { mc_receive_sockets[i].fd = mc_receive_socket_entries[i].fd; mc_receive_sockets[i].events = POLLIN | POLLPRI; @@ -875,7 +872,7 @@ static void *mc_receive_thread (void *arg) /* {{{ */ break; } - for (i = 0; i < mc_receive_sockets_num; i++) + for (size_t i = 0; i < mc_receive_sockets_num; i++) { if (mc_receive_sockets[i].revents != 0) mc_handle_socket (mc_receive_sockets + i); @@ -963,7 +960,6 @@ static int gmond_config_set_string (oconfig_item_t *ci, char **str) /* {{{ */ static int gmond_config_add_metric (oconfig_item_t *ci) /* {{{ */ { metric_map_t *map; - int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { @@ -995,7 +991,7 @@ static int gmond_config_add_metric (oconfig_item_t *ci) /* {{{ */ return (-1); } - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Type", child->key) == 0) @@ -1072,9 +1068,7 @@ static int gmond_config_set_address (oconfig_item_t *ci, /* {{{ */ static int gmond_config (oconfig_item_t *ci) /* {{{ */ { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("MCReceiveFrom", child->key) == 0) @@ -1112,12 +1106,10 @@ static int gmond_init (void) /* {{{ */ static int gmond_shutdown (void) /* {{{ */ { - size_t i; - mc_receive_thread_stop (); pthread_mutex_lock (&mc_send_sockets_lock); - for (i = 0; i < mc_send_sockets_num; i++) + for (size_t i = 0; i < mc_send_sockets_num; i++) { close (mc_send_sockets[i].fd); mc_send_sockets[i].fd = -1; diff --git a/src/hddtemp.c b/src/hddtemp.c index 2b481f51..8213e972 100644 --- a/src/hddtemp.c +++ b/src/hddtemp.c @@ -89,7 +89,7 @@ static int hddtemp_query_daemon (char *buffer, int buffer_size) const char *host; const char *port; - struct addrinfo *ai_list, *ai_ptr; + struct addrinfo *ai_list; int ai_return; host = hddtemp_host; @@ -119,7 +119,7 @@ static int hddtemp_query_daemon (char *buffer, int buffer_size) } fd = -1; - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { /* create our socket descriptor */ fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, @@ -250,7 +250,6 @@ static int hddtemp_read (void) char *saveptr; int num_fields; int num_disks; - int i; /* get data from daemon */ if (hddtemp_query_daemon (buf, sizeof (buf)) < 0) @@ -271,7 +270,7 @@ static int hddtemp_read (void) num_disks = num_fields / 4; - for (i = 0; i < num_disks; i++) + for (int i = 0; i < num_disks; i++) { char *name; double temperature; diff --git a/src/interface.c b/src/interface.c index 3024313a..a74699ee 100644 --- a/src/interface.c +++ b/src/interface.c @@ -192,7 +192,6 @@ static int interface_read (void) { #if HAVE_GETIFADDRS struct ifaddrs *if_list; - struct ifaddrs *if_ptr; /* Darwin/Mac OS X and possible other *BSDs */ #if HAVE_STRUCT_IF_DATA @@ -222,7 +221,7 @@ static int interface_read (void) if (getifaddrs (&if_list) != 0) return (-1); - for (if_ptr = if_list; if_ptr != NULL; if_ptr = if_ptr->ifa_next) + for (struct ifaddrs *if_ptr = if_list; if_ptr != NULL; if_ptr = if_ptr->ifa_next) { if (if_ptr->ifa_addr != NULL && if_ptr->ifa_addr->sa_family == AF_LINK) { if_data = (struct IFA_DATA *) if_ptr->ifa_data; @@ -306,7 +305,6 @@ static int interface_read (void) /* #endif KERNEL_LINUX */ #elif HAVE_LIBKSTAT - int i; derive_t rx; derive_t tx; char iname[DATA_MAX_NAME_LEN]; @@ -314,7 +312,7 @@ static int interface_read (void) if (kc == NULL) return (-1); - for (i = 0; i < numif; i++) + for (int i = 0; i < numif; i++) { if (kstat_read (kc, ksp[i], NULL) == -1) continue; @@ -358,11 +356,11 @@ static int interface_read (void) #elif defined(HAVE_LIBSTATGRAB) sg_network_io_stats *ios; - int i, num; + int num; ios = sg_get_network_io_stats (&num); - for (i = 0; i < num; i++) { + for (int i = 0; i < num; i++) { if (!report_inactive && ios[i].rx == 0 && ios[i].tx == 0) continue; if_submit (ios[i].interface_name, "if_octets", ios[i].rx, ios[i].tx); @@ -371,7 +369,7 @@ static int interface_read (void) #elif defined(HAVE_PERFSTAT) perfstat_id_t id; - int i, ifs; + int ifs; if ((nif = perfstat_netinterface(NULL, NULL, sizeof(perfstat_netinterface_t), 0)) < 0) { @@ -397,7 +395,7 @@ static int interface_read (void) return (-1); } - for (i = 0; i < ifs; i++) + for (int i = 0; i < ifs; i++) { if (!report_inactive && ifstat[i].ipackets == 0 && ifstat[i].opackets == 0) continue; diff --git a/src/ipc.c b/src/ipc.c index 49519894..70c55dc1 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -237,14 +237,14 @@ static int ipc_read_sem (void) /* {{{ */ ipcinfo_sem_t *ipcinfo_sem; unsigned short sem_nsems=0; unsigned short sems=0; - int i,n; + int n; ipcinfo_sem = (ipcinfo_sem_t *)ipc_get_info(0, GET_IPCINFO_SEM_ALL, IPCINFO_SEM_VERSION, sizeof(ipcinfo_sem_t), &n); if (ipcinfo_sem == NULL) return -1; - for (i=0; ishm_segsz; } @@ -288,14 +288,14 @@ static int ipc_read_msg (void) /* {{{ */ uint32_t msg_used_space=0; uint32_t msg_alloc_queues=0; msgqnum32_t msg_qnum=0; - int i,n; + int n; ipcinfo_msg = (ipcinfo_msg_t *)ipc_get_info(0, GET_IPCINFO_MSG_ALL, IPCINFO_MSG_VERSION, sizeof(ipcinfo_msg_t), &n); if (ipcinfo_msg == NULL) return -1; - for (i=0; inext) { diff --git a/src/iptables.c b/src/iptables.c index 7ff59c14..e035a888 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -420,12 +420,11 @@ static void submit_chain (iptc_handle_t *handle, ip_chain_t *chain) static int iptables_read (void) { - int i; int num_failures = 0; ip_chain_t *chain; /* Init the iptc handle structure and query the correct table */ - for (i = 0; i < chain_num; i++) + for (int i = 0; i < chain_num; i++) { chain = chain_list[i]; @@ -489,9 +488,7 @@ static int iptables_read (void) static int iptables_shutdown (void) { - int i; - - for (i = 0; i < chain_num; i++) + for (int i = 0; i < chain_num; i++) { if ((chain_list[i] != NULL) && (chain_list[i]->rule_type == RTYPE_COMMENT)) sfree (chain_list[i]->rule.comment); diff --git a/src/ipvs.c b/src/ipvs.c index 354c7d35..92690e88 100644 --- a/src/ipvs.c +++ b/src/ipvs.c @@ -292,8 +292,6 @@ static void cipvs_submit_service (struct ip_vs_service_entry *se) char pi[DATA_MAX_NAME_LEN]; - size_t i; - if (0 != get_pi (se, pi, sizeof (pi))) { free (dests); @@ -304,7 +302,7 @@ static void cipvs_submit_service (struct ip_vs_service_entry *se) cipvs_submit_if (pi, "if_packets", NULL, stats.inpkts, stats.outpkts); cipvs_submit_if (pi, "if_octets", NULL, stats.inbytes, stats.outbytes); - for (i = 0; i < dests->num_dests; ++i) + for (size_t i = 0; i < dests->num_dests; ++i) cipvs_submit_dest (pi, &dests->entrytable[i]); free (dests); @@ -314,7 +312,6 @@ static void cipvs_submit_service (struct ip_vs_service_entry *se) static int cipvs_read (void) { struct ip_vs_get_services *services = NULL; - size_t i; if (sockfd < 0) return (-1); @@ -322,7 +319,7 @@ static int cipvs_read (void) if (NULL == (services = ipvs_get_services ())) return -1; - for (i = 0; i < services->num_services; ++i) + for (size_t i = 0; i < services->num_services; ++i) cipvs_submit_service (&services->entrytable[i]); free (services); diff --git a/src/java.c b/src/java.c index 5e46f576..47f4cd36 100644 --- a/src/java.c +++ b/src/java.c @@ -507,7 +507,6 @@ static jobject ctoj_oconfig_item (JNIEnv *jvm_env, /* {{{ */ jmethodID m_addchild; jobject o_key; jobject o_ocitem; - int i; c_ocitem = (*jvm_env)->FindClass (jvm_env, "org/collectd/api/OConfigItem"); if (c_ocitem == NULL) @@ -572,7 +571,7 @@ static jobject ctoj_oconfig_item (JNIEnv *jvm_env, /* {{{ */ (*jvm_env)->DeleteLocalRef (jvm_env, o_key); /* Call OConfigItem.addValue for each value */ - for (i = 0; i < ci->values_num; i++) /* {{{ */ + for (int i = 0; i < ci->values_num; i++) /* {{{ */ { jobject o_value; @@ -590,7 +589,7 @@ static jobject ctoj_oconfig_item (JNIEnv *jvm_env, /* {{{ */ } /* }}} for (i = 0; i < ci->values_num; i++) */ /* Call OConfigItem.addChild for each child */ - for (i = 0; i < ci->children_num; i++) /* {{{ */ + for (int i = 0; i < ci->children_num; i++) /* {{{ */ { jobject o_child; @@ -618,7 +617,6 @@ static jobject ctoj_data_set (JNIEnv *jvm_env, const data_set_t *ds) /* {{{ */ jmethodID m_add; jobject o_type; jobject o_dataset; - size_t i; /* Look up the org/collectd/api/DataSet class */ c_dataset = (*jvm_env)->FindClass (jvm_env, "org/collectd/api/DataSet"); @@ -668,7 +666,7 @@ static jobject ctoj_data_set (JNIEnv *jvm_env, const data_set_t *ds) /* {{{ */ /* Decrease reference counter on the java.lang.String object. */ (*jvm_env)->DeleteLocalRef (jvm_env, o_type); - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { jobject o_datasource; @@ -763,7 +761,6 @@ static jobject ctoj_value_list (JNIEnv *jvm_env, /* {{{ */ jmethodID m_valuelist_constructor; jobject o_valuelist; int status; - size_t i; /* First, create a new ValueList instance.. * Look up the class.. */ @@ -846,7 +843,7 @@ static jobject ctoj_value_list (JNIEnv *jvm_env, /* {{{ */ return (NULL); } - for (i = 0; i < vl->values_len; i++) + for (size_t i = 0; i < vl->values_len; i++) { status = ctoj_value_list_add_value (jvm_env, vl->values[i], ds->ds[i].type, c_valuelist, o_valuelist); @@ -1117,7 +1114,6 @@ static int jtoc_values_array (JNIEnv *jvm_env, /* {{{ */ value_t *values; int values_num; - int i; values_num = ds->ds_num; @@ -1177,7 +1173,7 @@ static int jtoc_values_array (JNIEnv *jvm_env, /* {{{ */ BAIL_OUT (-1); } - for (i = 0; i < values_num; i++) + for (int i = 0; i < values_num; i++) { jobject o_number; int status; @@ -1980,7 +1976,6 @@ static int cjni_create_jvm (void) /* {{{ */ JavaVMOption vm_options[jvm_argc]; int status; - size_t i; if (jvm != NULL) return (0); @@ -1999,7 +1994,7 @@ static int cjni_create_jvm (void) /* {{{ */ vm_args.options = vm_options; vm_args.nOptions = (jint) jvm_argc; - for (i = 0; i < jvm_argc; i++) + for (size_t i = 0; i < jvm_argc; i++) { DEBUG ("java plugin: cjni_create_jvm: jvm_argv[%zu] = %s", i, jvm_argv[i]); @@ -2216,8 +2211,7 @@ static int cjni_config_load_plugin (oconfig_item_t *ci) /* {{{ */ { /* Replace all dots ('.') with slashes ('/'). Dots are usually used thorough the Java community, but (Sun's) `FindClass' and friends need slashes. */ - size_t i; - for (i = 0; class->name[i] != 0; i++) + for (size_t i = 0; class->name[i] != 0; i++) if (class->name[i] == '.') class->name[i] = '/'; } @@ -2275,7 +2269,6 @@ static int cjni_config_plugin_block (oconfig_item_t *ci) /* {{{ */ cjni_callback_info_t *cbi; jobject o_ocitem; const char *name; - size_t i; jclass class; jmethodID method; @@ -2290,7 +2283,7 @@ static int cjni_config_plugin_block (oconfig_item_t *ci) /* {{{ */ name = ci->values[0].value.string; cbi = NULL; - for (i = 0; i < java_callbacks_num; i++) + for (size_t i = 0; i < java_callbacks_num; i++) { if (java_callbacks[i].type != CB_TYPE_CONFIG) continue; @@ -2342,12 +2335,11 @@ static int cjni_config_perform (oconfig_item_t *ci) /* {{{ */ int success; int errors; int status; - int i; success = 0; errors = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -2710,7 +2702,6 @@ static int cjni_match_target_create (const oconfig_item_t *ci, /* {{{ */ jobject o_ci; jobject o_tmp; int type; - size_t i; cbi_ret = NULL; o_ci = NULL; @@ -2755,7 +2746,7 @@ static int cjni_match_target_create (const oconfig_item_t *ci, /* {{{ */ /* Lets see if we have a matching factory here.. */ cbi_factory = NULL; - for (i = 0; i < java_callbacks_num; i++) + for (size_t i = 0; i < java_callbacks_num; i++) { if (java_callbacks[i].type != type) continue; @@ -2937,9 +2928,8 @@ static int cjni_match_target_invoke (const data_set_t *ds, /* {{{ */ static int cjni_init_plugins (JNIEnv *jvm_env) /* {{{ */ { int status; - size_t i; - for (i = 0; i < java_callbacks_num; i++) + for (size_t i = 0; i < java_callbacks_num; i++) { if (java_callbacks[i].type != CB_TYPE_INIT) continue; @@ -2964,9 +2954,8 @@ static int cjni_init_plugins (JNIEnv *jvm_env) /* {{{ */ static int cjni_shutdown_plugins (JNIEnv *jvm_env) /* {{{ */ { int status; - size_t i; - for (i = 0; i < java_callbacks_num; i++) + for (size_t i = 0; i < java_callbacks_num; i++) { if (java_callbacks[i].type != CB_TYPE_SHUTDOWN) continue; @@ -2991,7 +2980,6 @@ static int cjni_shutdown (void) /* {{{ */ JNIEnv *jvm_env; JavaVMAttachArgs args = { 0 }; int status; - size_t i; if (jvm == NULL) return (0); @@ -3011,7 +2999,7 @@ static int cjni_shutdown (void) /* {{{ */ cjni_shutdown_plugins (jvm_env); /* Release all the global references to callback functions */ - for (i = 0; i < java_callbacks_num; i++) + for (size_t i = 0; i < java_callbacks_num; i++) { if (java_callbacks[i].object != NULL) { @@ -3024,7 +3012,7 @@ static int cjni_shutdown (void) /* {{{ */ sfree (java_callbacks); /* Release all the global references to directly loaded classes. */ - for (i = 0; i < java_classes_list_len; i++) + for (size_t i = 0; i < java_classes_list_len; i++) { if (java_classes_list[i].object != NULL) { @@ -3045,7 +3033,7 @@ static int cjni_shutdown (void) /* {{{ */ pthread_key_delete (jvm_env_key); /* Free the JVM argument list */ - for (i = 0; i < jvm_argc; i++) + for (size_t i = 0; i < jvm_argc; i++) sfree (jvm_argv[i]); jvm_argc = 0; sfree (jvm_argv); diff --git a/src/libcollectdclient/client.c b/src/libcollectdclient/client.c index cd333cc3..1c118e3c 100644 --- a/src/libcollectdclient/client.c +++ b/src/libcollectdclient/client.c @@ -235,12 +235,10 @@ static void lcc_chomp (char *str) /* {{{ */ static void lcc_response_free (lcc_response_t *res) /* {{{ */ { - size_t i; - if (res == NULL) return; - for (i = 0; i < res->lines_num; i++) + for (size_t i = 0; i < res->lines_num; i++) free (res->lines[i]); free (res->lines); res->lines = NULL; @@ -421,7 +419,6 @@ static int lcc_open_netsocket (lcc_connection_t *c, /* {{{ */ const char *addr_orig) { struct addrinfo *ai_res; - struct addrinfo *ai_ptr; char addr_copy[NI_MAXHOST]; char *addr; char *port; @@ -486,7 +483,7 @@ static int lcc_open_netsocket (lcc_connection_t *c, /* {{{ */ return (-1); } - for (ai_ptr = ai_res; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_res; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol); if (fd < 0) @@ -741,7 +738,6 @@ int lcc_putval (lcc_connection_t *c, const lcc_value_list_t *vl) /* {{{ */ char command[1024] = ""; lcc_response_t res; int status; - size_t i; if ((c == NULL) || (vl == NULL) || (vl->values_len < 1) || (vl->values == NULL) || (vl->values_types == NULL)) @@ -766,7 +762,7 @@ int lcc_putval (lcc_connection_t *c, const lcc_value_list_t *vl) /* {{{ */ else SSTRCAT (command, " N"); - for (i = 0; i < vl->values_len; i++) + for (size_t i = 0; i < vl->values_len; i++) { if (vl->values_types[i] == LCC_TYPE_COUNTER) SSTRCATF (command, ":%"PRIu64, vl->values[i].counter); @@ -858,7 +854,6 @@ int lcc_listval (lcc_connection_t *c, /* {{{ */ lcc_identifier_t **ret_ident, size_t *ret_ident_num) { lcc_response_t res; - size_t i; int status; lcc_identifier_t *ident; @@ -893,7 +888,7 @@ int lcc_listval (lcc_connection_t *c, /* {{{ */ return (-1); } - for (i = 0; i < res.lines_num; i++) + for (size_t i = 0; i < res.lines_num; i++) { char *time_str; char *ident_str; diff --git a/src/libcollectdclient/network.c b/src/libcollectdclient/network.c index ee5af3b5..16293ca0 100644 --- a/src/libcollectdclient/network.c +++ b/src/libcollectdclient/network.c @@ -120,7 +120,6 @@ static void int_server_destroy (lcc_server_t *srv) /* {{{ */ static int server_open_socket (lcc_server_t *srv) /* {{{ */ { struct addrinfo *ai_list; - struct addrinfo *ai_ptr; int status; if (srv == NULL) @@ -140,7 +139,7 @@ static int server_open_socket (lcc_server_t *srv) /* {{{ */ return (status); assert (ai_list != NULL); - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { srv->fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol); if (srv->fd < 0) @@ -470,12 +469,10 @@ int lcc_server_set_security_level (lcc_server_t *srv, /* {{{ */ int lcc_network_values_send (lcc_network_t *net, /* {{{ */ const lcc_value_list_t *vl) { - lcc_server_t *srv; - if ((net == NULL) || (vl == NULL)) return (EINVAL); - for (srv = net->servers; srv != NULL; srv = srv->next) + for (lcc_server_t *srv = net->servers; srv != NULL; srv = srv->next) server_value_add (srv, vl); return (0); diff --git a/src/libcollectdclient/network_buffer.c b/src/libcollectdclient/network_buffer.c index 9a9c89ac..2c6277c8 100644 --- a/src/libcollectdclient/network_buffer.c +++ b/src/libcollectdclient/network_buffer.c @@ -274,7 +274,6 @@ static int nb_add_values (char **ret_buffer, /* {{{ */ value_t pkg_values[vl->values_len]; size_t offset; - size_t i; packet_len = sizeof (pkg_type) + sizeof (pkg_length) + sizeof (pkg_num_values) @@ -288,7 +287,7 @@ static int nb_add_values (char **ret_buffer, /* {{{ */ pkg_length = htons ((uint16_t) packet_len); pkg_num_values = htons ((uint16_t) vl->values_len); - for (i = 0; i < vl->values_len; i++) + for (size_t i = 0; i < vl->values_len; i++) { pkg_values_types[i] = (uint8_t) vl->values_types[i]; switch (vl->values_types[i]) diff --git a/src/liboconfig/oconfig.c b/src/liboconfig/oconfig.c index cfe9c5a1..319aae85 100644 --- a/src/liboconfig/oconfig.c +++ b/src/liboconfig/oconfig.c @@ -126,8 +126,6 @@ oconfig_item_t *oconfig_clone (const oconfig_item_t *ci_orig) if (ci_orig->values_num > 0) /* {{{ */ { - int i; - ci_copy->values = (oconfig_value_t *) calloc ((size_t) ci_orig->values_num, sizeof (*ci_copy->values)); if (ci_copy->values == NULL) @@ -139,7 +137,7 @@ oconfig_item_t *oconfig_clone (const oconfig_item_t *ci_orig) } ci_copy->values_num = ci_orig->values_num; - for (i = 0; i < ci_copy->values_num; i++) + for (int i = 0; i < ci_copy->values_num; i++) { ci_copy->values[i].type = ci_orig->values[i].type; if (ci_copy->values[i].type == OCONFIG_TYPE_STRING) @@ -161,8 +159,6 @@ oconfig_item_t *oconfig_clone (const oconfig_item_t *ci_orig) if (ci_orig->children_num > 0) /* {{{ */ { - int i; - ci_copy->children = (oconfig_item_t *) calloc ((size_t) ci_orig->children_num, sizeof (*ci_copy->children)); if (ci_copy->children == NULL) @@ -173,7 +169,7 @@ oconfig_item_t *oconfig_clone (const oconfig_item_t *ci_orig) } ci_copy->children_num = ci_orig->children_num; - for (i = 0; i < ci_copy->children_num; i++) + for (int i = 0; i < ci_copy->children_num; i++) { oconfig_item_t *child; @@ -194,15 +190,13 @@ oconfig_item_t *oconfig_clone (const oconfig_item_t *ci_orig) static void oconfig_free_all (oconfig_item_t *ci) { - int i; - if (ci == NULL) return; if (ci->key != NULL) free (ci->key); - for (i = 0; i < ci->values_num; i++) + for (int i = 0; i < ci->values_num; i++) if ((ci->values[i].type == OCONFIG_TYPE_STRING) && (NULL != ci->values[i].value.string)) free (ci->values[i].value.string); @@ -210,7 +204,7 @@ static void oconfig_free_all (oconfig_item_t *ci) if (ci->values != NULL) free (ci->values); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) oconfig_free_all (ci->children + i); if (ci->children != NULL) diff --git a/src/liboconfig/parser.y b/src/liboconfig/parser.y index 1eb7aece..4a550b32 100644 --- a/src/liboconfig/parser.y +++ b/src/liboconfig/parser.y @@ -239,7 +239,6 @@ static char *unquote (const char *orig) { char *ret = strdup (orig); int len; - int i; if (ret == NULL) return (NULL); @@ -253,7 +252,7 @@ static char *unquote (const char *orig) memmove (ret, ret + 1, len); ret[len] = '\0'; - for (i = 0; i < len; i++) + for (int i = 0; i < len; i++) { if (ret[i] == '\\') { diff --git a/src/madwifi.c b/src/madwifi.c index 19ece7fe..728fcd8c 100644 --- a/src/madwifi.c +++ b/src/madwifi.c @@ -395,8 +395,7 @@ static inline void watchlist_remove (uint32_t *wl, int item) static inline void watchlist_set (uint32_t *wl, uint32_t val) { - int i; - for (i = 0; i < WL_LEN; i++) + for (int i = 0; i < WL_LEN; i++) wl[i] = val; } @@ -404,9 +403,8 @@ static inline void watchlist_set (uint32_t *wl, uint32_t val) static int watchitem_find (const char *name) { int max = STATIC_ARRAY_SIZE (specs); - int i; - for (i = 0; i < max; i++) + for (int i = 0; i < max; i++) if (strcasecmp (name, specs[i].name) == 0) return i; @@ -421,15 +419,14 @@ static int watchitem_find (const char *name) static int madwifi_real_init (void) { size_t max = STATIC_ARRAY_SIZE (specs); - size_t i; - for (i = 0; i < STATIC_ARRAY_SIZE (bounds); i++) + for (size_t i = 0; i < STATIC_ARRAY_SIZE (bounds); i++) bounds[i] = 0; watchlist_set(watch_items, 0); watchlist_set(misc_items, 0); - for (i = 0; i < max; i++) + for (size_t i = 0; i < max; i++) { bounds[specs[i].flags & SRC_MASK] = i; @@ -440,7 +437,7 @@ static int madwifi_real_init (void) misc_items[i / 32] |= FLAG (i); } - for (i = 0; i < STATIC_ARRAY_SIZE (bounds); i++) + for (size_t i = 0; i < STATIC_ARRAY_SIZE (bounds); i++) bounds[i]++; return (0); @@ -590,9 +587,8 @@ static void submit_antx (const char *dev, const char *name, u_int32_t *vals, int vals_num) { char ti2[16]; - int i; - for (i = 0; i < vals_num; i++) + for (int i = 0; i < vals_num; i++) { if (vals[i] == 0) continue; @@ -615,12 +611,11 @@ process_stat_struct (int which, const void *ptr, const char *dev, const char *ma const char *type_name, const char *misc_name) { uint32_t misc = 0; - int i; assert (which >= 1); assert (((size_t) which) < STATIC_ARRAY_SIZE (bounds)); - for (i = bounds[which - 1]; i < bounds[which]; i++) + for (int i = bounds[which - 1]; i < bounds[which]; i++) { uint32_t val = *(uint32_t *)(((char *) ptr) + specs[i].offset) ; diff --git a/src/match_empty_counter.c b/src/match_empty_counter.c index f4b94ee5..80a29ac7 100644 --- a/src/match_empty_counter.c +++ b/src/match_empty_counter.c @@ -56,9 +56,8 @@ static int mec_match (__attribute__((unused)) const data_set_t *ds, /* {{{ */ { int num_counters = 0; int num_empty = 0; - size_t i; - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { if ((ds->ds[i].type != DS_TYPE_DERIVE) && (ds->ds[i].type != DS_TYPE_COUNTER)) diff --git a/src/match_hashed.c b/src/match_hashed.c index 994022e6..c4983c2e 100644 --- a/src/match_hashed.c +++ b/src/match_hashed.c @@ -99,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) @@ -108,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; @@ -150,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); @@ -160,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); diff --git a/src/match_regex.c b/src/match_regex.c index f7d5e3e7..cd630167 100644 --- a/src/match_regex.c +++ b/src/match_regex.c @@ -100,12 +100,10 @@ static void mr_free_match (mr_match_t *m) /* {{{ */ static int mr_match_regexen (mr_regex_t *re_head, /* {{{ */ const char *string) { - mr_regex_t *re; - if (re_head == NULL) return (FC_MATCH_MATCHES); - for (re = re_head; re != NULL; re = re->next) + for (mr_regex_t *re = re_head; re != NULL; re = re->next) { int status; @@ -192,7 +190,6 @@ static int mr_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ { mr_match_t *m; int status; - int i; m = calloc (1, sizeof (*m)); if (m == NULL) @@ -204,7 +201,7 @@ static int mr_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ m->invert = 0; status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/match_timediff.c b/src/match_timediff.c index 9e08021b..00fdd0c1 100644 --- a/src/match_timediff.c +++ b/src/match_timediff.c @@ -50,7 +50,6 @@ static int mt_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ { mt_match_t *m; int status; - int i; m = calloc (1, sizeof (*m)); if (m == NULL) @@ -63,7 +62,7 @@ static int mt_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ m->past = 0; status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/match_value.c b/src/match_value.c index 604f0d6f..54ddba28 100644 --- a/src/match_value.c +++ b/src/match_value.c @@ -59,14 +59,12 @@ struct mv_match_s */ static void mv_free_match (mv_match_t *m) /* {{{ */ { - size_t i; - if (m == NULL) return; if (m->data_sources != NULL) { - for (i = 0; i < m->data_sources_num; ++i) + for (size_t i = 0; i < m->data_sources_num; ++i) free(m->data_sources[i]); free(m->data_sources); } @@ -104,7 +102,6 @@ static int mv_config_add_data_source (mv_match_t *m, /* {{{ */ { size_t new_data_sources_num; char **temp; - int i; /* Check number of arbuments. */ if (ci->values_num < 1) @@ -115,7 +112,7 @@ static int mv_config_add_data_source (mv_match_t *m, /* {{{ */ } /* Check type of arguments */ - for (i = 0; i < ci->values_num; i++) + for (int i = 0; i < ci->values_num; i++) { if (ci->values[i].type == OCONFIG_TYPE_STRING) continue; @@ -140,14 +137,12 @@ static int mv_config_add_data_source (mv_match_t *m, /* {{{ */ m->data_sources = temp; /* Copy the strings, allocating memory as needed. */ - for (i = 0; i < ci->values_num; i++) + for (int i = 0; i < ci->values_num; i++) { - size_t j; - /* If we get here, there better be memory for us to write to. */ assert (m->data_sources_num < new_data_sources_num); - j = m->data_sources_num; + size_t j = m->data_sources_num; m->data_sources[j] = sstrdup (ci->values[i].value.string); if (m->data_sources[j] == NULL) { @@ -199,7 +194,6 @@ static int mv_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ { mv_match_t *m; int status; - int i; m = calloc (1, sizeof (*m)); if (m == NULL) @@ -216,7 +210,7 @@ static int mv_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ m->data_sources_num = 0; status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -277,7 +271,6 @@ static int mv_match (const data_set_t *ds, const value_list_t *vl, /* {{{ */ mv_match_t *m; gauge_t *values; int status; - size_t i; if ((user_data == NULL) || (*user_data == NULL)) return (-1); @@ -294,7 +287,7 @@ static int mv_match (const data_set_t *ds, const value_list_t *vl, /* {{{ */ status = FC_MATCH_NO_MATCH; - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { int value_matches = 0; diff --git a/src/mbmon.c b/src/mbmon.c index 2e26aa1f..184bb994 100644 --- a/src/mbmon.c +++ b/src/mbmon.c @@ -85,7 +85,7 @@ static int mbmon_query_daemon (char *buffer, int buffer_size) const char *host; const char *port; - struct addrinfo *ai_list, *ai_ptr; + struct addrinfo *ai_list; int ai_return; host = mbmon_host; @@ -115,7 +115,7 @@ static int mbmon_query_daemon (char *buffer, int buffer_size) } fd = -1; - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { /* create our socket descriptor */ if ((fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol)) < 0) @@ -237,9 +237,7 @@ static void mbmon_submit (const char *type, const char *type_instance, /* Trim trailing whitespace from a string. */ static void trim_spaces (char *s) { - size_t l; - - for (l = strlen (s) - 1; (l > 0) && isspace ((int) s[l]); l--) + for (size_t l = strlen (s) - 1; (l > 0) && isspace ((int) s[l]); l--) s[l] = '\0'; } diff --git a/src/memcachec.c b/src/memcachec.c index 55e9b855..1b6ab673 100644 --- a/src/memcachec.c +++ b/src/memcachec.c @@ -200,7 +200,6 @@ static int cmc_config_add_match (web_page_t *page, /* {{{ */ { web_match_t *match; int status; - int i; if (ci->values_num != 0) { @@ -215,7 +214,7 @@ static int cmc_config_add_match (web_page_t *page, /* {{{ */ } status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -297,7 +296,6 @@ static int cmc_config_add_page (oconfig_item_t *ci) /* {{{ */ { web_page_t *page; int status; - int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { @@ -324,7 +322,7 @@ static int cmc_config_add_page (oconfig_item_t *ci) /* {{{ */ /* Process all children */ status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -401,12 +399,11 @@ static int cmc_config (oconfig_item_t *ci) /* {{{ */ int success; int errors; int status; - int i; success = 0; errors = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -465,7 +462,6 @@ static void cmc_submit (const web_page_t *wp, const web_match_t *wm, /* {{{ */ static int cmc_read_page (web_page_t *wp) /* {{{ */ { - web_match_t *wm; memcached_return rc; size_t string_length; uint32_t flags; @@ -483,7 +479,7 @@ static int cmc_read_page (web_page_t *wp) /* {{{ */ return (-1); } - for (wm = wp->matches; wm != NULL; wm = wm->next) + for (web_match_t *wm = wp->matches; wm != NULL; wm = wm->next) { cu_match_value_t *mv; @@ -512,9 +508,7 @@ static int cmc_read_page (web_page_t *wp) /* {{{ */ static int cmc_read (void) /* {{{ */ { - web_page_t *wp; - - for (wp = pages_g; wp != NULL; wp = wp->next) + for (web_page_t *wp = pages_g; wp != NULL; wp = wp->next) cmc_read_page (wp); return (0); diff --git a/src/memcached.c b/src/memcached.c index e398dd9e..dbc020ac 100644 --- a/src/memcached.c +++ b/src/memcached.c @@ -102,7 +102,7 @@ static int memcached_connect_inet (memcached_t *st) const char *host; const char *port; - struct addrinfo *ai_list, *ai_ptr; + struct addrinfo *ai_list; int status; int fd = -1; @@ -128,7 +128,7 @@ static int memcached_connect_inet (memcached_t *st) return (-1); } - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { /* create our socket descriptor */ fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol); @@ -575,7 +575,6 @@ static int memcached_add_read_callback (memcached_t *st) static int config_add_instance(oconfig_item_t *ci) { memcached_t *st; - int i; int status = 0; /* Disable automatic generation of default instance in the init callback. */ @@ -604,7 +603,7 @@ static int config_add_instance(oconfig_item_t *ci) } assert (st->name != NULL); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -641,9 +640,8 @@ static int memcached_config (oconfig_item_t *ci) { int status = 0; _Bool have_instance_block = 0; - int i; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/memory.c b/src/memory.c index 6204d35c..16b8e09f 100644 --- a/src/memory.c +++ b/src/memory.c @@ -99,9 +99,7 @@ static _Bool values_percentage = 0; static int memory_config (oconfig_item_t *ci) /* {{{ */ { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("ValuesAbsolute", child->key) == 0) @@ -251,9 +249,7 @@ static int memory_read_internal (value_list_t *vl) }; double sysctl_vals[8]; - int i; - - for (i = 0; sysctl_keys[i] != NULL; i++) + for (int i = 0; sysctl_keys[i] != NULL; i++) { int value; size_t value_len = sizeof (value); @@ -271,7 +267,7 @@ static int memory_read_internal (value_list_t *vl) } /* for (sysctl_keys) */ /* multiply all all page counts with the pagesize */ - for (i = 1; sysctl_keys[i] != NULL; i++) + for (int i = 1; sysctl_keys[i] != NULL; i++) if (!isnan (sysctl_vals[i])) sysctl_vals[i] *= sysctl_vals[0]; diff --git a/src/mic.c b/src/mic.c index 8d7871b1..3e31889f 100644 --- a/src/mic.c +++ b/src/mic.c @@ -214,9 +214,8 @@ static void mic_submit_temp(int micnumber, const char *type, gauge_t val) static int mic_read_temps(int mic) { size_t num_therms = STATIC_ARRAY_SIZE(therm_ids); - size_t j; - for (j = 0; j < num_therms; j++) { + for (size_t j = 0; j < num_therms; j++) { U32 status; U32 temp_buffer; U32 buffer_size = (U32)sizeof(temp_buffer); @@ -287,8 +286,7 @@ static int mic_read_cpu(int mic) } if (show_cpu_cores) { - int j; - for (j = 0; j < core_util.core; j++) { + for (int j = 0; j < core_util.core; j++) { mic_submit_cpu(mic, "user", j, core_jiffs[j].user); mic_submit_cpu(mic, "sys", j, core_jiffs[j].sys); mic_submit_cpu(mic, "nice", j, core_jiffs[j].nice); @@ -357,12 +355,11 @@ static int mic_read_power(int mic) static int mic_read (void) { - int i; U32 ret; int error; error=0; - for (i=0;inext) + for (mb_data_t *ptr = src; ptr != NULL; ptr = ptr->next) if (strcasecmp (ptr->name, name) == 0) return (ptr); @@ -622,7 +620,6 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */ static int mb_read_slave (mb_host_t *host, mb_slave_t *slave) /* {{{ */ { - mb_data_t *data; int success; int status; @@ -630,7 +627,7 @@ static int mb_read_slave (mb_host_t *host, mb_slave_t *slave) /* {{{ */ return (EINVAL); success = 0; - for (data = slave->collect; data != NULL; data = data->next) + for (mb_data_t *data = slave->collect; data != NULL; data = data->next) { status = mb_read_data (host, slave, data); if (status == 0) @@ -646,7 +643,6 @@ static int mb_read_slave (mb_host_t *host, mb_slave_t *slave) /* {{{ */ static int mb_read (user_data_t *user_data) /* {{{ */ { mb_host_t *host; - size_t i; int success; int status; @@ -656,7 +652,7 @@ static int mb_read (user_data_t *user_data) /* {{{ */ host = user_data->data; success = 0; - for (i = 0; i < host->slaves_num; i++) + for (size_t i = 0; i < host->slaves_num; i++) { status = mb_read_slave (host, host->slaves + i); if (status == 0) @@ -695,12 +691,10 @@ static void data_free_all (mb_data_t *data) /* {{{ */ static void slaves_free_all (mb_slave_t *slaves, size_t slaves_num) /* {{{ */ { - size_t i; - if (slaves == NULL) return; - for (i = 0; i < slaves_num; i++) + for (size_t i = 0; i < slaves_num; i++) data_free_all (slaves[i].collect); sfree (slaves); } /* }}} void slaves_free_all */ @@ -722,7 +716,6 @@ static int mb_config_add_data (oconfig_item_t *ci) /* {{{ */ { mb_data_t data = { 0 }; int status; - int i; data.name = NULL; data.register_type = REG_TYPE_UINT16; @@ -732,7 +725,7 @@ static int mb_config_add_data (oconfig_item_t *ci) /* {{{ */ if (status != 0) return (status); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -818,7 +811,6 @@ static int mb_config_set_host_address (mb_host_t *host, /* {{{ */ const char *address) { struct addrinfo *ai_list; - struct addrinfo *ai_ptr; int status; if ((host == NULL) || (address == NULL)) @@ -842,7 +834,7 @@ static int mb_config_set_host_address (mb_host_t *host, /* {{{ */ return (status); } - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { status = getnameinfo (ai_ptr->ai_addr, ai_ptr->ai_addrlen, host->node, sizeof (host->node), @@ -869,7 +861,6 @@ static int mb_config_add_slave (mb_host_t *host, oconfig_item_t *ci) /* {{{ */ { mb_slave_t *slave; int status; - int i; if ((host == NULL) || (ci == NULL)) return (EINVAL); @@ -886,7 +877,7 @@ static int mb_config_add_slave (mb_host_t *host, oconfig_item_t *ci) /* {{{ */ if (status != 0) return (status); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -929,7 +920,6 @@ static int mb_config_add_host (oconfig_item_t *ci) /* {{{ */ { mb_host_t *host; int status; - int i; host = calloc (1, sizeof (*host)); if (host == NULL) @@ -948,7 +938,7 @@ static int mb_config_add_host (oconfig_item_t *ci) /* {{{ */ return (EINVAL); } - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; status = 0; @@ -1037,12 +1027,10 @@ static int mb_config_add_host (oconfig_item_t *ci) /* {{{ */ static int mb_config (oconfig_item_t *ci) /* {{{ */ { - int i; - if (ci == NULL) return (EINVAL); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/mqtt.c b/src/mqtt.c index 5667ff44..a7a0b86d 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -145,11 +145,9 @@ static void mqtt_free (mqtt_client_conf_t *conf) static char *strip_prefix (char *topic) { - size_t num; - size_t i; + size_t num = 0; - num = 0; - for (i = 0; topic[i] != 0; i++) + for (size_t i = 0; topic[i] != 0; i++) if (topic[i] == '/') num++; @@ -552,7 +550,6 @@ static int mqtt_config_publisher (oconfig_item_t *ci) char cb_name[1024]; user_data_t user_data = { 0 }; int status; - int i; conf = calloc (1, sizeof (*conf)); if (conf == NULL) @@ -586,7 +583,7 @@ static int mqtt_config_publisher (oconfig_item_t *ci) C_COMPLAIN_INIT (&conf->complaint_cantpublish); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Host", child->key) == 0) @@ -656,7 +653,6 @@ static int mqtt_config_subscriber (oconfig_item_t *ci) mqtt_client_conf_t **tmp; mqtt_client_conf_t *conf; int status; - int i; conf = calloc (1, sizeof (*conf)); if (conf == NULL) @@ -690,7 +686,7 @@ static int mqtt_config_subscriber (oconfig_item_t *ci) C_COMPLAIN_INIT (&conf->complaint_cantpublish); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Host", child->key) == 0) @@ -752,9 +748,7 @@ static int mqtt_config_subscriber (oconfig_item_t *ci) */ static int mqtt_config (oconfig_item_t *ci) { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -771,11 +765,9 @@ static int mqtt_config (oconfig_item_t *ci) static int mqtt_init (void) { - size_t i; - mosquitto_lib_init (); - for (i = 0; i < subscribers_num; i++) + for (size_t i = 0; i < subscribers_num; i++) { int status; diff --git a/src/multimeter.c b/src/multimeter.c index 491e6413..02fe1ad3 100644 --- a/src/multimeter.c +++ b/src/multimeter.c @@ -149,10 +149,9 @@ static int multimeter_read_value(double *value) static int multimeter_init (void) { - int i; char device[] = "/dev/ttyS "; - for (i = 0; i < 10; i++) + for (int i = 0; i < 10; i++) { device[strlen(device)-1] = i + '0'; diff --git a/src/mysql.c b/src/mysql.c index 54236dac..1bc0fdf7 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -104,7 +104,6 @@ static int mysql_config_database (oconfig_item_t *ci) /* {{{ */ { mysql_database_t *db; int status = 0; - int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) @@ -144,7 +143,7 @@ static int mysql_config_database (oconfig_item_t *ci) /* {{{ */ assert (db->instance != NULL); /* Fill the `mysql_database_t' structure.. */ - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -222,13 +221,11 @@ static int mysql_config_database (oconfig_item_t *ci) /* {{{ */ static int mysql_config (oconfig_item_t *ci) /* {{{ */ { - int i; - if (ci == NULL) return (EINVAL); /* Fill the `mysql_database_t' structure.. */ - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/netapp.c b/src/netapp.c index dbf02850..26577dad 100644 --- a/src/netapp.c +++ b/src/netapp.c @@ -894,7 +894,6 @@ static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* const char *plugin_inst; na_elem_t *instances; - na_elem_t *counter; na_elem_iter_t counter_iter; perf_data.timestamp = cna_child_get_cdtime (data); @@ -919,7 +918,7 @@ static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* /* Iterate over all counters */ counter_iter = na_child_iterator (na_elem_child (instances, "counters")); - for (counter = na_iterator_next (&counter_iter); + for (na_elem_t *counter = na_iterator_next (&counter_iter); counter != NULL; counter = na_iterator_next (&counter_iter)) { @@ -1055,7 +1054,6 @@ static int cna_handle_disk_data (const char *hostname, /* {{{ */ { cdtime_t timestamp; na_elem_t *instances; - na_elem_t *instance; na_elem_iter_t instance_iter; disk_t *worst_disk = NULL; @@ -1075,7 +1073,7 @@ static int cna_handle_disk_data (const char *hostname, /* {{{ */ /* Iterate over all children */ instance_iter = na_child_iterator (instances); - for (instance = na_iterator_next (&instance_iter); + for (na_elem_t *instance = na_iterator_next (&instance_iter); instance != NULL; instance = na_iterator_next(&instance_iter)) { @@ -1083,7 +1081,6 @@ static int cna_handle_disk_data (const char *hostname, /* {{{ */ disk_t new_data = { 0 }; na_elem_iter_t counter_iterator; - na_elem_t *counter; new_data.timestamp = timestamp; new_data.disk_busy_percent = NAN; @@ -1094,7 +1091,7 @@ static int cna_handle_disk_data (const char *hostname, /* {{{ */ /* Look for the "disk_busy" and "base_for_disk_busy" counters */ counter_iterator = na_child_iterator(na_elem_child(instance, "counters")); - for (counter = na_iterator_next(&counter_iterator); + for (na_elem_t *counter = na_iterator_next(&counter_iterator); counter != NULL; counter = na_iterator_next(&counter_iterator)) { @@ -1251,7 +1248,6 @@ static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */ cdtime_t timestamp; na_elem_t *elem_instances; na_elem_iter_t iter_instances; - na_elem_t *elem_instance; timestamp = cna_child_get_cdtime (data); @@ -1265,7 +1261,7 @@ static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */ } iter_instances = na_child_iterator (elem_instances); - for (elem_instance = na_iterator_next(&iter_instances); + for (na_elem_t *elem_instance = na_iterator_next(&iter_instances); elem_instance != NULL; elem_instance = na_iterator_next(&iter_instances)) { @@ -1276,7 +1272,6 @@ static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */ na_elem_t *elem_counters; na_elem_iter_t iter_counters; - na_elem_t *elem_counter; perf_data.timestamp = timestamp; @@ -1294,7 +1289,7 @@ static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */ continue; iter_counters = na_child_iterator (elem_counters); - for (elem_counter = na_iterator_next(&iter_counters); + for (na_elem_t *elem_counter = na_iterator_next(&iter_counters); elem_counter != NULL; elem_counter = na_iterator_next(&iter_counters)) { @@ -1419,9 +1414,7 @@ static int cna_query_volume_perf (host_config_t *host) /* {{{ */ static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */ cfg_volume_usage_t *cfg_volume, int interval) { - data_volume_usage_t *v; - - for (v = cfg_volume->volumes; v != NULL; v = v->next) + for (data_volume_usage_t *v = cfg_volume->volumes; v != NULL; v = v->next) { char plugin_instance[DATA_MAX_NAME_LEN]; @@ -1542,7 +1535,7 @@ static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */ data_volume_usage_t *v) { uint64_t snap_used = 0, value; - na_elem_t *data, *elem_snap, *elem_snapshots; + na_elem_t *data, *elem_snapshots; na_elem_iter_t iter_snap; data = na_server_invoke_elem(host->srv, v->snap_query); @@ -1574,7 +1567,7 @@ static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */ } iter_snap = na_child_iterator (elem_snapshots); - for (elem_snap = na_iterator_next (&iter_snap); + for (na_elem_t *elem_snap = na_iterator_next (&iter_snap); elem_snap != NULL; elem_snap = na_iterator_next (&iter_snap)) { @@ -1689,7 +1682,6 @@ static void cna_handle_volume_sis_saved (const host_config_t *host, /* {{{ */ static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */ cfg_volume_usage_t *cfg_volume, na_elem_t *data) { - na_elem_t *elem_volume; na_elem_t *elem_volumes; na_elem_iter_t iter_volume; @@ -1703,7 +1695,7 @@ static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */ } iter_volume = na_child_iterator (elem_volumes); - for (elem_volume = na_iterator_next (&iter_volume); + for (na_elem_t *elem_volume = na_iterator_next (&iter_volume); elem_volume != NULL; elem_volume = na_iterator_next (&iter_volume)) { @@ -1827,7 +1819,6 @@ static int cna_query_volume_usage (host_config_t *host) /* {{{ */ static int cna_handle_quota_data (const host_config_t *host, /* {{{ */ cfg_quota_t *cfg_quota, na_elem_t *data) { - na_elem_t *elem_quota; na_elem_t *elem_quotas; na_elem_iter_t iter_quota; @@ -1841,7 +1832,7 @@ static int cna_handle_quota_data (const host_config_t *host, /* {{{ */ } iter_quota = na_child_iterator (elem_quotas); - for (elem_quota = na_iterator_next (&iter_quota); + for (na_elem_t *elem_quota = na_iterator_next (&iter_quota); elem_quota != NULL; elem_quota = na_iterator_next (&iter_quota)) { @@ -1953,7 +1944,6 @@ static int cna_query_quota (host_config_t *host) /* {{{ */ static int cna_handle_snapvault_data (const char *hostname, /* {{{ */ cfg_snapvault_t *cfg_snapvault, na_elem_t *data, cdtime_t interval) { - na_elem_t *status; na_elem_iter_t status_iter; status = na_elem_child (data, "status-list"); @@ -1963,7 +1953,7 @@ static int cna_handle_snapvault_data (const char *hostname, /* {{{ */ } status_iter = na_child_iterator (status); - for (status = na_iterator_next (&status_iter); + for (na_elem_t *status = na_iterator_next (&status_iter); status != NULL; status = na_iterator_next (&status_iter)) { @@ -2013,7 +2003,6 @@ static int cna_handle_snapvault_iter (host_config_t *host, /* {{{ */ const char *tag; uint32_t records_count; - uint32_t i; records_count = na_child_get_uint32 (data, "records", UINT32_MAX); if (records_count == UINT32_MAX) @@ -2025,7 +2014,7 @@ static int cna_handle_snapvault_iter (host_config_t *host, /* {{{ */ DEBUG ("netapp plugin: Iterating %u SV records (tag = %s)", records_count, tag); - for (i = 0; i < records_count; ++i) { + for (uint32_t i = 0; i < records_count; ++i) { na_elem_t *elem; elem = na_server_invoke (host->srv, @@ -2114,7 +2103,6 @@ static int cna_handle_system_data (const char *hostname, /* {{{ */ cfg_system_t *cfg_system, na_elem_t *data, int interval) { na_elem_t *instances; - na_elem_t *counter; na_elem_iter_t counter_iter; derive_t disk_read = 0, disk_written = 0; @@ -2146,7 +2134,7 @@ static int cna_handle_system_data (const char *hostname, /* {{{ */ } counter_iter = na_child_iterator (na_elem_child (instances, "counters")); - for (counter = na_iterator_next (&counter_iter); + for (na_elem_t *counter = na_iterator_next (&counter_iter); counter != NULL; counter = na_iterator_next (&counter_iter)) { @@ -2391,7 +2379,6 @@ static int cna_config_volume_performance (host_config_t *host, /* {{{ */ const oconfig_item_t *ci) { cfg_volume_perf_t *cfg_volume_perf; - int i; if ((host == NULL) || (ci == NULL)) return (EINVAL); @@ -2434,7 +2421,7 @@ static int cna_config_volume_performance (host_config_t *host, /* {{{ */ } cfg_volume_perf = host->cfg_volume_perf; - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *item = ci->children + i; /* if (!item || !item->key || !*item->key) continue; */ @@ -2518,7 +2505,6 @@ static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */ static int cna_config_quota (host_config_t *host, oconfig_item_t *ci) /* {{{ */ { cfg_quota_t *cfg_quota; - int i; if ((host == NULL) || (ci == NULL)) return (EINVAL); @@ -2534,7 +2520,7 @@ static int cna_config_quota (host_config_t *host, oconfig_item_t *ci) /* {{{ */ } cfg_quota = host->cfg_quota; - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *item = ci->children + i; if (strcasecmp (item->key, "Interval") == 0) @@ -2550,7 +2536,6 @@ static int cna_config_quota (host_config_t *host, oconfig_item_t *ci) /* {{{ */ /* Corresponds to a block */ static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */ cfg_disk_t *cfg_disk; - int i; if ((host == NULL) || (ci == NULL)) return (EINVAL); @@ -2570,7 +2555,7 @@ static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */ } cfg_disk = host->cfg_disk; - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *item = ci->children + i; /* if (!item || !item->key || !*item->key) continue; */ @@ -2595,7 +2580,6 @@ static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */ static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */ { cfg_wafl_t *cfg_wafl; - int i; if ((host == NULL) || (ci == NULL)) return (EINVAL); @@ -2613,7 +2597,7 @@ static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */ } cfg_wafl = host->cfg_wafl; - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *item = ci->children + i; if (strcasecmp(item->key, "Interval") == 0) @@ -2663,7 +2647,6 @@ static int cna_config_volume_usage(host_config_t *host, /* {{{ */ const oconfig_item_t *ci) { cfg_volume_usage_t *cfg_volume_usage; - int i; if ((host == NULL) || (ci == NULL)) return (EINVAL); @@ -2697,7 +2680,7 @@ static int cna_config_volume_usage(host_config_t *host, /* {{{ */ } cfg_volume_usage = host->cfg_volume_usage; - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *item = ci->children + i; /* if (!item || !item->key || !*item->key) continue; */ @@ -2724,7 +2707,6 @@ static int cna_config_snapvault (host_config_t *host, /* {{{ */ const oconfig_item_t *ci) { cfg_snapvault_t *cfg_snapvault; - int i; if ((host == NULL) || (ci == NULL)) return EINVAL; @@ -2741,7 +2723,7 @@ static int cna_config_snapvault (host_config_t *host, /* {{{ */ cfg_snapvault = host->cfg_snapvault; - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *item = ci->children + i; if (strcasecmp (item->key, "Interval") == 0) @@ -2759,7 +2741,6 @@ static int cna_config_system (host_config_t *host, /* {{{ */ oconfig_item_t *ci) { cfg_system_t *cfg_system; - int i; if ((host == NULL) || (ci == NULL)) return (EINVAL); @@ -2778,7 +2759,7 @@ static int cna_config_system (host_config_t *host, /* {{{ */ } cfg_system = host->cfg_system; - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *item = ci->children + i; if (strcasecmp(item->key, "Interval") == 0) { @@ -2916,7 +2897,6 @@ static int cna_config_host (host_config_t *host, /* {{{ */ oconfig_item_t *item; _Bool is_vfiler = 0; int status; - int i; if (! strcasecmp (ci->key, "VFiler")) is_vfiler = 1; @@ -2930,7 +2910,7 @@ static int cna_config_host (host_config_t *host, /* {{{ */ if (status != 0) return (1); - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { item = ci->children + i; status = 0; @@ -3139,10 +3119,9 @@ static int cna_read (user_data_t *ud) { /* {{{ */ } /* }}} int cna_read */ static int cna_config (oconfig_item_t *ci) { /* {{{ */ - int i; oconfig_item_t *item; - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { item = ci->children + i; if (strcasecmp(item->key, "Host") == 0) diff --git a/src/netlink.c b/src/netlink.c index b2c8b0f2..cfca46f7 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -157,14 +157,12 @@ static int add_ignorelist (const char *dev, const char *type, static int check_ignorelist (const char *dev, const char *type, const char *type_instance) { - ir_ignorelist_t *i; - assert ((dev != NULL) && (type != NULL)); if (ir_ignorelist_head == NULL) return (ir_ignorelist_invert ? 0 : 1); - for (i = ir_ignorelist_head; i != NULL; i = i->next) + for (ir_ignorelist_t *i = ir_ignorelist_head; i != NULL; i = i->next) { /* i->device == NULL => match all devices */ if ((i->device != NULL) @@ -725,8 +723,6 @@ static int ir_read (void) int ret; unsigned int seq, portid; - size_t ifindex; - static const int type_id[] = { RTM_GETQDISC, RTM_GETTCLASS, RTM_GETTFILTER }; static const char *type_name[] = { "qdisc", "class", "filter" }; @@ -761,15 +757,14 @@ static int ir_read (void) /* `link_filter_cb' will update `iflist' which is used here to iterate * over all interfaces. */ - for (ifindex = 1; ifindex < iflist_len; ifindex++) + for (size_t ifindex = 1; ifindex < iflist_len; ifindex++) { struct tcmsg *tm; - size_t type_index; if (iflist[ifindex] == NULL) continue; - for (type_index = 0; type_index < STATIC_ARRAY_SIZE (type_id); type_index++) + for (size_t type_index = 0; type_index < STATIC_ARRAY_SIZE (type_id); type_index++) { if (check_ignorelist (iflist[ifindex], type_name[type_index], NULL)) { diff --git a/src/network.c b/src/network.c index 3fa66aab..1b560c47 100644 --- a/src/network.c +++ b/src/network.c @@ -370,9 +370,7 @@ static _Bool check_send_okay (const value_list_t *vl) /* {{{ */ static _Bool check_notify_received (const notification_t *n) /* {{{ */ { - notification_meta_t *ptr; - - for (ptr = n->meta; ptr != NULL; ptr = ptr->next) + for (notification_meta_t *ptr = n->meta; ptr != NULL; ptr = ptr->next) if ((strcmp ("network:received", ptr->name) == 0) && (ptr->type == NM_TYPE_BOOLEAN)) return ((_Bool) ptr->nm_value.nm_boolean); @@ -619,7 +617,6 @@ static int write_part_values (char **ret_buffer, size_t *ret_buffer_len, value_t *pkg_values; size_t offset; - int i; num_values = vl->values_len; packet_len = sizeof (part_header_t) + sizeof (uint16_t) @@ -649,7 +646,7 @@ static int write_part_values (char **ret_buffer, size_t *ret_buffer_len, pkg_num_values = htons ((uint16_t) vl->values_len); - for (i = 0; i < num_values; i++) + for (int i = 0; i < num_values; i++) { pkg_values_types[i] = (uint8_t) ds->ds[i].type; switch (ds->ds[i].type) @@ -787,7 +784,6 @@ static int parse_part_values (void **ret_buffer, size_t *ret_buffer_len, uint16_t tmp16; size_t exp_size; - size_t i; uint16_t pkg_length; uint16_t pkg_type; @@ -853,7 +849,7 @@ static int parse_part_values (void **ret_buffer, size_t *ret_buffer_len, memcpy (pkg_values, buffer, pkg_numval * sizeof (*pkg_values)); buffer += pkg_numval * sizeof (*pkg_values); - for (i = 0; i < pkg_numval; i++) + for (size_t i = 0; i < pkg_numval; i++) { switch (pkg_types[i]) { @@ -1651,9 +1647,7 @@ static void free_sockent_client (struct sockent_client *sec) /* {{{ */ static void free_sockent_server (struct sockent_server *ses) /* {{{ */ { - size_t i; - - for (i = 0; i < ses->fd_num; i++) + for (size_t i = 0; i < ses->fd_num; i++) { if (ses->fd[i] >= 0) { @@ -2140,7 +2134,7 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */ static c_complain_t complaint = C_COMPLAIN_INIT_STATIC; struct sockent_client *client; - struct addrinfo *ai_list, *ai_ptr; + struct addrinfo *ai_list; int status; _Bool reconnect = 0; cdtime_t now; @@ -2186,7 +2180,7 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */ se->node); } - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { if (client->fd >= 0) /* when we reconnect */ sockent_client_disconnect(se); @@ -2236,7 +2230,7 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */ /* Open the file descriptors for a initialized sockent structure. */ static int sockent_server_listen (sockent_t *se) /* {{{ */ { - struct addrinfo *ai_list, *ai_ptr; + struct addrinfo *ai_list; int status; const char *node; @@ -2274,7 +2268,7 @@ static int sockent_server_listen (sockent_t *se) /* {{{ */ return (-1); } - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { int *tmp; @@ -2329,7 +2323,6 @@ static int sockent_add (sockent_t *se) /* {{{ */ if (se->type == SOCKENT_TYPE_SERVER) { struct pollfd *tmp; - size_t i; tmp = realloc (listen_sockets_pollfd, sizeof (*tmp) * (listen_sockets_num @@ -2342,7 +2335,7 @@ static int sockent_add (sockent_t *se) /* {{{ */ listen_sockets_pollfd = tmp; tmp = listen_sockets_pollfd + listen_sockets_num; - for (i = 0; i < se->data.server.fd_num; i++) + for (size_t i = 0; i < se->data.server.fd_num; i++) { memset (tmp + i, 0, sizeof (*tmp)); tmp[i].fd = se->data.server.fd[i]; @@ -2441,7 +2434,6 @@ static int network_receive (void) /* {{{ */ char buffer[network_config_packet_size]; int buffer_len; - size_t i; int status = 0; receive_list_entry_t *private_list_head; @@ -2467,7 +2459,7 @@ static int network_receive (void) /* {{{ */ break; } - for (i = 0; (i < listen_sockets_num) && (status > 0); i++) + for (size_t i = 0; (i < listen_sockets_num) && (status > 0); i++) { receive_list_entry_t *ent; @@ -2785,11 +2777,9 @@ static void network_send_buffer_encrypted (sockent_t *se, /* {{{ */ static void network_send_buffer (char *buffer, size_t buffer_len) /* {{{ */ { - sockent_t *se; - DEBUG ("network plugin: network_send_buffer: buffer_len = %zu", buffer_len); - for (se = sending_sockets; se != NULL; se = se->next) + for (sockent_t *se = sending_sockets; se != NULL; se = se->next) { #if HAVE_LIBGCRYPT if (se->data.client.security_level == SECURITY_LEVEL_ENCRYPT) @@ -3036,7 +3026,6 @@ static int network_config_add_listen (const oconfig_item_t *ci) /* {{{ */ { sockent_t *se; int status; - int i; if ((ci->values_num < 1) || (ci->values_num > 2) || (ci->values[0].type != OCONFIG_TYPE_STRING) @@ -3058,7 +3047,7 @@ static int network_config_add_listen (const oconfig_item_t *ci) /* {{{ */ if (ci->values_num >= 2) se->service = strdup (ci->values[1].value.string); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -3122,7 +3111,6 @@ static int network_config_add_server (const oconfig_item_t *ci) /* {{{ */ { sockent_t *se; int status; - int i; if ((ci->values_num < 1) || (ci->values_num > 2) || (ci->values[0].type != OCONFIG_TYPE_STRING) @@ -3144,7 +3132,7 @@ static int network_config_add_server (const oconfig_item_t *ci) /* {{{ */ if (ci->values_num >= 2) se->service = strdup (ci->values[1].value.string); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -3206,17 +3194,15 @@ static int network_config_add_server (const oconfig_item_t *ci) /* {{{ */ static int network_config (oconfig_item_t *ci) /* {{{ */ { - int i; - /* The options need to be applied first */ - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("TimeToLive", child->key) == 0) network_config_set_ttl (child); } - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -3319,8 +3305,6 @@ static int network_notification (const notification_t *n, static int network_shutdown (void) { - sockent_t *se; - listen_loop++; /* Kill the listening thread */ @@ -3351,7 +3335,7 @@ static int network_shutdown (void) sfree (send_buffer); - for (se = sending_sockets; se != NULL; se = se->next) + for (sockent_t *se = sending_sockets; se != NULL; se = se->next) sockent_client_disconnect (se); sockent_destroy (sending_sockets); diff --git a/src/nfs.c b/src/nfs.c index ee2d93b2..c128c817 100644 --- a/src/nfs.c +++ b/src/nfs.c @@ -346,8 +346,6 @@ static int nfs_init (void) #elif HAVE_LIBKSTAT static int nfs_init (void) { - kstat_t *ksp_chain = NULL; - nfs2_ksp_client = NULL; nfs2_ksp_server = NULL; nfs3_ksp_client = NULL; @@ -358,7 +356,7 @@ static int nfs_init (void) if (kc == NULL) return (-1); - for (ksp_chain = kc->kc_chain; ksp_chain != NULL; + for (kstat_t *ksp_chain = kc->kc_chain; ksp_chain != NULL; ksp_chain = ksp_chain->ks_next) { if (strncmp (ksp_chain->ks_module, "nfs", 3) != 0) @@ -386,7 +384,6 @@ static void nfs_procedures_submit (const char *plugin_instance, value_t *values, size_t values_num) { value_list_t vl = VALUE_LIST_INIT; - size_t i; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); @@ -395,7 +392,7 @@ static void nfs_procedures_submit (const char *plugin_instance, sizeof (vl.plugin_instance)); sstrncpy (vl.type, "nfs_procedure", sizeof (vl.type)); - for (i = 0; i < values_num; i++) + for (size_t i = 0; i < values_num; i++) { vl.values = values + i; sstrncpy (vl.type_instance, type_instances[i], @@ -410,12 +407,11 @@ static void nfs_submit_fields (int nfs_version, const char *instance, { char plugin_instance[DATA_MAX_NAME_LEN]; value_t values[fields_num]; - size_t i; ssnprintf (plugin_instance, sizeof (plugin_instance), "v%i%s", nfs_version, instance); - for (i = 0; i < fields_num; i++) + for (size_t i = 0; i < fields_num; i++) (void) parse_value (fields[i], &values[i], DS_TYPE_DERIVE); nfs_procedures_submit (plugin_instance, proc_names, values, @@ -609,7 +605,6 @@ static int nfs_read_kstat (kstat_t *ksp, int nfs_version, const char *inst, { char plugin_instance[DATA_MAX_NAME_LEN]; value_t values[proc_names_num]; - size_t i; if (ksp == NULL) return (EINVAL); @@ -618,7 +613,7 @@ static int nfs_read_kstat (kstat_t *ksp, int nfs_version, const char *inst, nfs_version, inst); kstat_read(kc, ksp, NULL); - for (i = 0; i < proc_names_num; i++) + for (size_t i = 0; i < proc_names_num; i++) { /* The name passed to kstat_data_lookup() doesn't have the * "const" modifier, so we need to copy the name here. */ diff --git a/src/nginx.c b/src/nginx.c index 2c7e1ccd..e346cee3 100644 --- a/src/nginx.c +++ b/src/nginx.c @@ -225,8 +225,6 @@ static void submit (const char *type, const char *inst, long long value) static int nginx_read (void) { - int i; - char *ptr; char *lines[16]; int lines_num = 0; @@ -264,7 +262,7 @@ static int nginx_read (void) * 16630948 16630948 31070465 * Reading: 6 Writing: 179 Waiting: 106 */ - for (i = 0; i < lines_num; i++) + for (int i = 0; i < lines_num; i++) { fields_num = strsplit (lines[i], fields, (sizeof (fields) / sizeof (fields[0]))); diff --git a/src/notify_desktop.c b/src/notify_desktop.c index d12ecb2c..ef7b95b8 100644 --- a/src/notify_desktop.c +++ b/src/notify_desktop.c @@ -67,9 +67,7 @@ static int set_timeout (oconfig_item_t *ci, int *timeout) static int c_notify_config (oconfig_item_t *ci) { - int i = 0; - - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *c = ci->children + i; if (0 == strcasecmp (c->key, "OkayTimeout")) diff --git a/src/notify_email.c b/src/notify_email.c index c7fe79ea..cefeb22f 100644 --- a/src/notify_email.c +++ b/src/notify_email.c @@ -67,8 +67,7 @@ static char *email_subject = NULL; static int authinteract (auth_client_request_t request, char **result, int fields, void __attribute__((unused)) *arg) { - int i; - for (i = 0; i < fields; i++) + for (int i = 0; i < fields; i++) { if (request[i].flags & AUTH_USER) result[i] = smtp_user; diff --git a/src/notify_nagios.c b/src/notify_nagios.c index c53294b2..57a034da 100644 --- a/src/notify_nagios.c +++ b/src/notify_nagios.c @@ -43,9 +43,7 @@ static char *nagios_command_file; static int nagios_config (oconfig_item_t *ci) /* {{{ */ { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/ntpd.c b/src/ntpd.c index 02c9f6dc..a0093655 100644 --- a/src/ntpd.c +++ b/src/ntpd.c @@ -348,7 +348,6 @@ static int ntpd_connect (void) const char *port; struct addrinfo *ai_list; - struct addrinfo *ai_ptr; int status; if (sock_descr >= 0) @@ -382,7 +381,7 @@ static int ntpd_connect (void) return (-1); } - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { /* create our socket descriptor */ if ((sock_descr = socket (ai_ptr->ai_family, @@ -420,7 +419,6 @@ static int ntpd_receive_response (int *res_items, int *res_size, struct resp_pkt res; int status; int done; - int i; char *items; size_t items_num; @@ -674,7 +672,7 @@ static int ntpd_receive_response (int *res_items, int *res_size, items_num += pkt_item_num; *res_data = items; - for (i = 0; i < pkt_item_num; i++) + for (int i = 0; i < pkt_item_num; i++) { /* dst: There are already `*res_items' items with * res_item_size bytes each in in `*res_data'. Set @@ -903,7 +901,6 @@ static int ntpd_read (void) gauge_t offset_error; int status; - int i; /* On Linux, if the STA_NANO bit is set in ik->status, then ik->offset * is is nanoseconds, otherwise it's microseconds. */ @@ -971,7 +968,7 @@ static int ntpd_read (void) return (-1); } - for (i = 0; i < ps_num; i++) + for (int i = 0; i < ps_num; i++) { struct info_peer_summary *ptr; double offset; diff --git a/src/nut.c b/src/nut.c index ee96863b..b5c6b41b 100644 --- a/src/nut.c +++ b/src/nut.c @@ -248,7 +248,6 @@ static int nut_read_one (nut_ups_t *ups) static int nut_read (void) { - nut_ups_t *ups; int success = 0; pthread_mutex_lock (&read_lock); @@ -259,7 +258,7 @@ static int nut_read (void) if (success != 0) return (0); - for (ups = upslist_head; ups != NULL; ups = ups->next) + for (nut_ups_t *ups = upslist_head; ups != NULL; ups = ups->next) if (nut_read_one (ups) == 0) success++; diff --git a/src/olsrd.c b/src/olsrd.c index 0af32dc1..899ad3e8 100644 --- a/src/olsrd.c +++ b/src/olsrd.c @@ -150,7 +150,7 @@ static size_t strtabsplit (char *string, char **fields, size_t size) /* {{{ */ static FILE *olsrd_connect (void) /* {{{ */ { - struct addrinfo *ai_list, *ai_ptr; + struct addrinfo *ai_list; int ai_return; FILE *fh; @@ -173,7 +173,7 @@ static FILE *olsrd_connect (void) /* {{{ */ } fh = NULL; - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { int fd; int status; diff --git a/src/onewire.c b/src/onewire.c index f1030867..235eff80 100644 --- a/src/onewire.c +++ b/src/onewire.c @@ -339,7 +339,6 @@ static int cow_read_values (const char *path, const char *name, value_t values[1]; value_list_t vl = VALUE_LIST_INIT; int success = 0; - size_t i; if (sensor_list != NULL) { @@ -355,7 +354,7 @@ static int cow_read_values (const char *path, const char *name, sstrncpy (vl.plugin, "onewire", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, name, sizeof (vl.plugin_instance)); - for (i = 0; i < family_info->features_num; i++) + for (size_t i = 0; i < family_info->features_num; i++) { char *buffer; size_t buffer_size; diff --git a/src/openldap.c b/src/openldap.c index 35eae32e..282e2dc7 100644 --- a/src/openldap.c +++ b/src/openldap.c @@ -209,7 +209,7 @@ static void cldap_submit_gauge (const char *type, const char *type_instance, /* static int cldap_read_host (user_data_t *ud) /* {{{ */ { cldap_t *st; - LDAPMessage *e, *result; + LDAPMessage *result; char *dn; int rc; int status; @@ -250,7 +250,7 @@ static int cldap_read_host (user_data_t *ud) /* {{{ */ return (-1); } - for (e = ldap_first_entry (st->ld, result); e != NULL; + for (LDAPMessage *e = ldap_first_entry (st->ld, result); e != NULL; e = ldap_next_entry (st->ld, e)) { if ((dn = ldap_get_dn (st->ld, e)) != NULL) @@ -559,7 +559,6 @@ static int cldap_read_host (user_data_t *ud) /* {{{ */ static int cldap_config_add (oconfig_item_t *ci) /* {{{ */ { cldap_t *st; - int i; int status; st = calloc (1, sizeof (*st)); @@ -581,7 +580,7 @@ static int cldap_config_add (oconfig_item_t *ci) /* {{{ */ st->verifyhost = 1; st->version = LDAP_VERSION3; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -687,10 +686,9 @@ static int cldap_config_add (oconfig_item_t *ci) /* {{{ */ static int cldap_config (oconfig_item_t *ci) /* {{{ */ { - int i; int status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -720,9 +718,7 @@ static int cldap_init (void) /* {{{ */ static int cldap_shutdown (void) /* {{{ */ { - size_t i; - - for (i = 0; i < databases_num; i++) + for (size_t i = 0; i < databases_num; i++) if (databases[i]->ld != NULL) ldap_unbind_ext_s (databases[i]->ld, NULL, NULL); sfree (databases); diff --git a/src/openvpn.c b/src/openvpn.c index 8bbb82b2..00ae736a 100644 --- a/src/openvpn.c +++ b/src/openvpn.c @@ -522,12 +522,12 @@ static int multi4_read (const char *name, FILE *fh) static int openvpn_read (void) { FILE *fh; - int i, read; + int read; read = 0; /* call the right read function for every status entry in the list */ - for (i = 0; i < vpn_num; i++) + for (int i = 0; i < vpn_num; i++) { int vpn_read = 0; @@ -651,7 +651,7 @@ static int openvpn_config (const char *key, const char *value) if (strcasecmp ("StatusFile", key) == 0) { char *status_file, *status_name, *filename; - int status_version, i; + int status_version; vpn_status_t *temp; /* try to detect the status file format */ @@ -687,7 +687,7 @@ static int openvpn_config (const char *key, const char *value) } /* scan the list looking for a clone */ - for (i = 0; i < vpn_num; i++) + for (int i = 0; i < vpn_num; i++) { if (strcasecmp (vpn_list[i]->name, status_name) == 0) { @@ -778,9 +778,7 @@ static int openvpn_config (const char *key, const char *value) /* shutdown callback */ static int openvpn_shutdown (void) { - int i; - - for (i = 0; i < vpn_num; i++) + for (int i = 0; i < vpn_num; i++) { sfree (vpn_list[i]->file); sfree (vpn_list[i]); diff --git a/src/oracle.c b/src/oracle.c index 8ecfe25a..15548300 100644 --- a/src/oracle.c +++ b/src/oracle.c @@ -94,7 +94,6 @@ static void o_report_error (const char *where, /* {{{ */ char buffer[2048]; sb4 error_code; int status; - unsigned int record_number; if (db_name == NULL) db_name = "(none)"; @@ -103,7 +102,7 @@ static void o_report_error (const char *where, /* {{{ */ /* An operation may cause / return multiple errors. Loop until we have * handled all errors available (with a fail-save limit of 16). */ - for (record_number = 1; record_number <= 16; record_number++) + for (unsigned int record_number = 1; record_number <= 16; record_number++) { memset (buffer, 0, sizeof (buffer)); error_code = -1; @@ -145,8 +144,6 @@ static void o_report_error (const char *where, /* {{{ */ static void o_database_free (o_database_t *db) /* {{{ */ { - size_t i; - if (db == NULL) return; @@ -157,7 +154,7 @@ static void o_database_free (o_database_t *db) /* {{{ */ sfree (db->queries); if (db->q_prep_areas != NULL) - for (i = 0; i < db->queries_num; ++i) + for (size_t i = 0; i < db->queries_num; ++i) udb_query_delete_preparation_area (db->q_prep_areas[i]); free (db->q_prep_areas); @@ -189,7 +186,6 @@ static int o_config_add_database (oconfig_item_t *ci) /* {{{ */ { o_database_t *db; int status; - int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) @@ -219,7 +215,7 @@ static int o_config_add_database (oconfig_item_t *ci) /* {{{ */ } /* Fill the `o_database_t' structure.. */ - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -278,7 +274,7 @@ static int o_config_add_database (oconfig_item_t *ci) /* {{{ */ break; } - for (i = 0; i < db->queries_num; ++i) + for (int i = 0; i < db->queries_num; ++i) { db->q_prep_areas[i] = udb_query_allocate_preparation_area (db->queries[i]); @@ -326,9 +322,7 @@ static int o_config_add_database (oconfig_item_t *ci) /* {{{ */ static int o_config (oconfig_item_t *ci) /* {{{ */ { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Query", child->key) == 0) @@ -400,7 +394,6 @@ static int o_read_database_query (o_database_t *db, /* {{{ */ OCIDefine **oci_defines; int status; - size_t i; oci_statement = udb_query_get_user_data (q); @@ -518,13 +511,13 @@ static int o_read_database_query (o_database_t *db, /* {{{ */ ALLOC_OR_FAIL (column_names, column_num * sizeof (char *)); ALLOC_OR_FAIL (column_names[0], column_num * DATA_MAX_NAME_LEN * sizeof (char)); - for (i = 1; i < column_num; i++) + for (size_t i = 1; i < column_num; i++) column_names[i] = column_names[i - 1] + DATA_MAX_NAME_LEN; ALLOC_OR_FAIL (column_values, column_num * sizeof (char *)); ALLOC_OR_FAIL (column_values[0], column_num * DATA_MAX_NAME_LEN * sizeof (char)); - for (i = 1; i < column_num; i++) + for (size_t i = 1; i < column_num; i++) column_values[i] = column_values[i - 1] + DATA_MAX_NAME_LEN; ALLOC_OR_FAIL (oci_defines, column_num * sizeof (OCIDefine *)); @@ -532,7 +525,7 @@ static int o_read_database_query (o_database_t *db, /* {{{ */ /* ``Define'' the returned data, i. e. bind the columns to the buffers * allocated above. */ - for (i = 0; i < column_num; i++) /* {{{ */ + for (size_t i = 0; i < column_num; i++) /* {{{ */ { char *column_name; ub4 column_name_length; @@ -643,7 +636,6 @@ static int o_read_database_query (o_database_t *db, /* {{{ */ static int o_read_database (o_database_t *db) /* {{{ */ { - size_t i; int status; if (db->oci_service_context != NULL) @@ -718,7 +710,7 @@ static int o_read_database (o_database_t *db) /* {{{ */ DEBUG ("oracle plugin: o_read_database: db->connect_id = %s; db->oci_service_context = %p;", db->connect_id, db->oci_service_context); - for (i = 0; i < db->queries_num; i++) + for (size_t i = 0; i < db->queries_num; i++) o_read_database_query (db, db->queries[i], db->q_prep_areas[i]); return (0); diff --git a/src/perl.c b/src/perl.c index d2f83455..48374b69 100644 --- a/src/perl.c +++ b/src/perl.c @@ -309,7 +309,6 @@ static int hv2data_source (pTHX_ HV *hash, data_source_t *ds) static size_t av2value (pTHX_ char *name, AV *array, value_t *value, size_t array_len) { const data_set_t *ds; - size_t i; if ((NULL == name) || (NULL == array) || (NULL == value) || (array_len == 0)) return 0; @@ -329,7 +328,7 @@ static size_t av2value (pTHX_ char *name, AV *array, value_t *value, size_t arra name, array_len, ds->ds_num); } - for (i = 0; i < ds->ds_num; ++i) { + for (size_t i = 0; i < ds->ds_num; ++i) { SV **tmp = av_fetch (array, i, 0); if (NULL != tmp) { @@ -428,7 +427,7 @@ static int hv2value_list (pTHX_ HV *hash, value_list_t *vl) static int av2data_set (pTHX_ AV *array, char *name, data_set_t *ds) { - int len, i; + int len; if ((NULL == array) || (NULL == name) || (NULL == ds)) return -1; @@ -443,7 +442,7 @@ static int av2data_set (pTHX_ AV *array, char *name, data_set_t *ds) ds->ds = smalloc ((len + 1) * sizeof (*ds->ds)); ds->ds_num = len + 1; - for (i = 0; i <= len; ++i) { + for (int i = 0; i <= len; ++i) { SV **elem = av_fetch (array, i, 0); if (NULL == elem) { @@ -487,9 +486,8 @@ static int av2notification_meta (pTHX_ AV *array, notification_meta_t **meta) notification_meta_t **m = meta; int len = av_len (array); - int i; - for (i = 0; i <= len; ++i) { + for (int i = 0; i <= len; ++i) { SV **tmp = av_fetch (array, i, 0); HV *hash; @@ -605,14 +603,12 @@ static int hv2notification (pTHX_ HV *hash, notification_t *n) static int data_set2av (pTHX_ data_set_t *ds, AV *array) { - size_t i; - if ((NULL == ds) || (NULL == array)) return -1; av_extend (array, ds->ds_num); - for (i = 0; i < ds->ds_num; ++i) { + for (size_t i = 0; i < ds->ds_num; ++i) { HV *source = newHV (); if (NULL == hv_store (source, "name", 4, @@ -712,7 +708,6 @@ static int value_list2hv (pTHX_ value_list_t *vl, data_set_t *ds, HV *hash) static int notification_meta2av (pTHX_ notification_meta_t *meta, AV *array) { int meta_num = 0; - int i; while (meta) { ++meta_num; @@ -721,7 +716,7 @@ static int notification_meta2av (pTHX_ notification_meta_t *meta, AV *array) av_extend (array, meta_num); - for (i = 0; NULL != meta; meta = meta->next, ++i) { + for (int i = 0; NULL != meta; meta = meta->next, ++i) { HV *m = newHV (); SV *value; @@ -808,8 +803,6 @@ static int notification2hv (pTHX_ notification_t *n, HV *hash) static int oconfig_item2hv (pTHX_ oconfig_item_t *ci, HV *hash) { - int i; - AV *values; AV *children; @@ -826,7 +819,7 @@ static int oconfig_item2hv (pTHX_ oconfig_item_t *ci, HV *hash) return -1; } - for (i = 0; i < ci->values_num; ++i) { + for (int i = 0; i < ci->values_num; ++i) { SV *value; switch (ci->values[i].type) { @@ -863,7 +856,7 @@ static int oconfig_item2hv (pTHX_ oconfig_item_t *ci, HV *hash) return -1; } - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { HV *child = newHV (); if (0 != oconfig_item2hv (aTHX_ ci->children + i, child)) { @@ -2239,21 +2232,19 @@ static void xs_init (pTHX) SV *tmp = NULL; char *file = __FILE__; - int i = 0; - dXSUB_SYS; /* enable usage of Perl modules using shared libraries */ newXS ("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); /* register API */ - for (i = 0; NULL != api[i].f; ++i) + for (int i = 0; NULL != api[i].f; ++i) newXS (api[i].name, api[i].f, file); stash = gv_stashpv ("Collectd", 1); /* export "constants" */ - for (i = 0; '\0' != constants[i].name[0]; ++i) + for (int i = 0; '\0' != constants[i].name[0]; ++i) newCONSTSUB (stash, constants[i].name, newSViv (constants[i].value)); /* export global variables @@ -2262,7 +2253,7 @@ static void xs_init (pTHX) * accessing any such variable (this is basically the same as using * tie() in Perl) */ /* global strings */ - for (i = 0; '\0' != g_strings[i].name[0]; ++i) { + for (int i = 0; '\0' != g_strings[i].name[0]; ++i) { tmp = get_sv (g_strings[i].name, 1); sv_magicext (tmp, NULL, PERL_MAGIC_ext, &g_pv_vtbl, g_strings[i].var, 0); @@ -2287,9 +2278,7 @@ static int init_pi (int argc, char **argv) log_info ("Initializing Perl interpreter..."); #if COLLECT_DEBUG { - int i = 0; - - for (i = 0; i < argc; ++i) + for (int i = 0; i < argc; ++i) log_debug ("argv[%i] = \"%s\"", i, argv[i]); } #endif /* COLLECT_DEBUG */ @@ -2558,11 +2547,10 @@ static int perl_config_plugin (pTHX_ oconfig_item_t *ci) static int perl_config (oconfig_item_t *ci) { int status = 0; - int i = 0; dTHXa (NULL); - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *c = ci->children + i; int current_status = 0; diff --git a/src/pf.c b/src/pf.c index e8e0b185..d7a5a15c 100644 --- a/src/pf.c +++ b/src/pf.c @@ -83,7 +83,6 @@ static int pf_read (void) struct pf_status state; int fd; int status; - int i; fd = open (pf_device, O_RDONLY); if (fd < 0) @@ -113,16 +112,16 @@ static int pf_read (void) return (-1); } - for (i = 0; i < PFRES_MAX; i++) + for (int i = 0; i < PFRES_MAX; i++) pf_submit ("pf_counters", pf_reasons[i], state.counters[i], /* is gauge = */ 0); - for (i = 0; i < LCNT_MAX; i++) + for (int i = 0; i < LCNT_MAX; i++) pf_submit ("pf_limits", pf_lcounters[i], state.lcounters[i], /* is gauge = */ 0); - for (i = 0; i < FCNT_MAX; i++) + for (int i = 0; i < FCNT_MAX; i++) pf_submit ("pf_state", pf_fcounters[i], state.fcounters[i], /* is gauge = */ 0); - for (i = 0; i < SCNT_MAX; i++) + for (int i = 0; i < SCNT_MAX; i++) pf_submit ("pf_source", pf_scounters[i], state.scounters[i], /* is gauge = */ 0); diff --git a/src/pinba.c b/src/pinba.c index 33ab545a..b9eed68e 100644 --- a/src/pinba.c +++ b/src/pinba.c @@ -252,11 +252,9 @@ static void service_statnode_process (pinba_statnode_t *node, /* {{{ */ static void service_process_request (Pinba__Request *request) /* {{{ */ { - unsigned int i; - pthread_mutex_lock (&stat_nodes_lock); - for (i = 0; i < stat_nodes_num; i++) + for (unsigned int i = 0; i < stat_nodes_num; i++) { if ((stat_nodes[i].host != NULL) && (strcmp (request->hostname, stat_nodes[i].host) != 0)) @@ -352,7 +350,6 @@ static pinba_socket_t *pinba_socket_open (const char *node, /* {{{ */ { pinba_socket_t *s; struct addrinfo *ai_list; - struct addrinfo *ai_ptr; int status; if (node == NULL) @@ -385,7 +382,7 @@ static pinba_socket_t *pinba_socket_open (const char *node, /* {{{ */ return (NULL); } - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { status = pb_add_socket (s, ai_ptr); if (status != 0) @@ -406,12 +403,10 @@ static pinba_socket_t *pinba_socket_open (const char *node, /* {{{ */ static void pinba_socket_free (pinba_socket_t *socket) /* {{{ */ { - nfds_t i; - if (!socket) return; - for (i = 0; i < socket->fd_num; i++) + for (nfds_t i = 0; i < socket->fd_num; i++) { if (socket->fd[i].fd < 0) continue; @@ -502,7 +497,6 @@ static int receive_loop (void) /* {{{ */ while (!collector_thread_do_shutdown) { int status; - nfds_t i; if (s->fd_num < 1) break; @@ -525,7 +519,7 @@ static int receive_loop (void) /* {{{ */ return (-1); } - for (i = 0; i < s->fd_num; i++) + for (nfds_t i = 0; i < s->fd_num; i++) { if (s->fd[i].revents & (POLLERR | POLLHUP | POLLNVAL)) { @@ -565,13 +559,12 @@ static int pinba_config_view (const oconfig_item_t *ci) /* {{{ */ char *server = NULL; char *script = NULL; int status; - int i; status = cf_util_get_string (ci, &name); if (status != 0) return (status); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -604,13 +597,11 @@ static int pinba_config_view (const oconfig_item_t *ci) /* {{{ */ static int plugin_config (oconfig_item_t *ci) /* {{{ */ { - int i; - /* The lock should not be necessary in the config callback, but let's be * sure.. */ pthread_mutex_lock (&stat_nodes_lock); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/ping.c b/src/ping.c index 0a9bc444..978cb490 100644 --- a/src/ping.c +++ b/src/ping.c @@ -152,11 +152,10 @@ static void time_calc (struct timespec *ts_dest, /* {{{ */ static int ping_dispatch_all (pingobj_t *pingobj) /* {{{ */ { - pingobj_iter_t *iter; hostlist_t *hl; int status; - for (iter = ping_iterator_get (pingobj); + for (pingobj_iter_t *iter = ping_iterator_get (pingobj); iter != NULL; iter = ping_iterator_next (iter)) { /* {{{ */ @@ -251,7 +250,6 @@ static void *ping_thread (void *arg) /* {{{ */ struct timespec ts_wait; struct timespec ts_int; - hostlist_t *hl; int count; c_complain_t complaint = C_COMPLAIN_INIT_STATIC; @@ -287,7 +285,7 @@ static void *ping_thread (void *arg) /* {{{ */ /* Add all the hosts to the ping object. */ count = 0; - for (hl = hostlist_head; hl != NULL; hl = hl->next) + for (hostlist_t *hl = hostlist_head; hl != NULL; hl = hl->next) { int tmp_status; tmp_status = ping_host_add (pingobj, hl->host); @@ -550,8 +548,6 @@ static int ping_config (const char *key, const char *value) /* {{{ */ /* Max IP packet size - (IPv6 + ICMP) = 65535 - (40 + 8) = 65487 */ if (size <= 65487) { - size_t i; - sfree (ping_data); ping_data = malloc (size + 1); if (ping_data == NULL) @@ -567,7 +563,7 @@ static int ping_config (const char *key, const char *value) /* {{{ */ * Optimally we would follow the ping(1) behaviour, but we * cannot use byte 00 or start data payload at exactly same * location, due to oping library limitations. */ - for (i = 0; i < size; i++) /* {{{ */ + for (size_t i = 0; i < size; i++) /* {{{ */ { /* This restricts data pattern to be only composed of easily * printable characters, and not NUL character. */ @@ -623,15 +619,13 @@ static void submit (const char *host, const char *type, /* {{{ */ static int ping_read (void) /* {{{ */ { - hostlist_t *hl; - if (ping_thread_error != 0) { ERROR ("ping plugin: The ping thread had a problem. Restarting it."); stop_thread (); - for (hl = hostlist_head; hl != NULL; hl = hl->next) + for (hostlist_t *hl = hostlist_head; hl != NULL; hl = hl->next) { hl->pkg_sent = 0; hl->pkg_recv = 0; @@ -644,7 +638,7 @@ static int ping_read (void) /* {{{ */ return (-1); } /* if (ping_thread_error != 0) */ - for (hl = hostlist_head; hl != NULL; hl = hl->next) /* {{{ */ + for (hostlist_t *hl = hostlist_head; hl != NULL; hl = hl->next) /* {{{ */ { uint32_t pkg_sent; uint32_t pkg_recv; diff --git a/src/postgresql.c b/src/postgresql.c index 3b125ee8..7e69877c 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -277,8 +277,6 @@ static c_psql_database_t *c_psql_database_new (const char *name) static void c_psql_database_delete (void *data) { - size_t i; - c_psql_database_t *db = data; --db->ref_cnt; @@ -296,7 +294,7 @@ static void c_psql_database_delete (void *data) db->conn = NULL; if (db->q_prep_areas) - for (i = 0; i < db->queries_num; ++i) + for (size_t i = 0; i < db->queries_num; ++i) udb_query_delete_preparation_area (db->q_prep_areas[i]); free (db->q_prep_areas); @@ -428,14 +426,13 @@ static PGresult *c_psql_exec_query_params (c_psql_database_t *db, { const char *params[db->max_params_num]; char interval[64]; - int i; if ((data == NULL) || (data->params_num == 0)) return (c_psql_exec_query_noparams (db, q)); assert (db->max_params_num >= data->params_num); - for (i = 0; i < data->params_num; ++i) { + for (int i = 0; i < data->params_num; ++i) { switch (data->params[i]) { case C_PSQL_PARAM_HOST: params[i] = C_PSQL_IS_UNIX_DOMAIN_SOCKET (db->host) @@ -484,7 +481,6 @@ static int c_psql_exec_query (c_psql_database_t *db, udb_query_t *q, int rows_num; int status; - int row, col; /* The user data may hold parameter information, but may be NULL. */ data = udb_query_get_user_data (q); @@ -553,7 +549,7 @@ static int c_psql_exec_query (c_psql_database_t *db, udb_query_t *q, BAIL_OUT (-1); } - for (col = 0; col < column_num; ++col) { + for (int col = 0; col < column_num; ++col) { /* Pointers returned by `PQfname' are freed by `PQclear' via * `BAIL_OUT'. */ column_names[col] = PQfname (res, col); @@ -578,7 +574,8 @@ static int c_psql_exec_query (c_psql_database_t *db, udb_query_t *q, BAIL_OUT (-1); } - for (row = 0; row < rows_num; ++row) { + for (int row = 0; row < rows_num; ++row) { + int col; for (col = 0; col < column_num; ++col) { /* Pointers returned by `PQgetvalue' are freed by `PQclear' via * `BAIL_OUT'. */ @@ -612,7 +609,6 @@ static int c_psql_read (user_data_t *ud) c_psql_database_t *db; int success = 0; - size_t i; if ((ud == NULL) || (ud->data == NULL)) { log_err ("c_psql_read: Invalid user data."); @@ -632,7 +628,7 @@ static int c_psql_read (user_data_t *ud) return -1; } - for (i = 0; i < db->queries_num; ++i) + for (size_t i = 0; i < db->queries_num; ++i) { udb_query_preparation_area_t *prep_area; udb_query_t *q; @@ -660,12 +656,11 @@ static char *values_name_to_sqlarray (const data_set_t *ds, { char *str_ptr; size_t str_len; - size_t i; str_ptr = string; str_len = string_len; - for (i = 0; i < ds->ds_num; ++i) { + for (size_t i = 0; i < ds->ds_num; ++i) { int status = ssnprintf (str_ptr, str_len, ",'%s'", ds->ds[i].name); if (status < 1) @@ -698,12 +693,11 @@ static char *values_type_to_sqlarray (const data_set_t *ds, { char *str_ptr; size_t str_len; - size_t i; str_ptr = string; str_len = string_len; - for (i = 0; i < ds->ds_num; ++i) { + for (size_t i = 0; i < ds->ds_num; ++i) { int status; if (store_rates) @@ -746,12 +740,11 @@ static char *values_to_sqlarray (const data_set_t *ds, const value_list_t *vl, size_t str_len; gauge_t *rates = NULL; - size_t i; str_ptr = string; str_len = string_len; - for (i = 0; i < vl->values_len; ++i) { + for (size_t i = 0; i < vl->values_len; ++i) { int status = 0; if ((ds->ds[i].type != DS_TYPE_GAUGE) @@ -831,7 +824,6 @@ static int c_psql_write (const data_set_t *ds, const value_list_t *vl, const char *params[9]; int success = 0; - size_t i; if ((ud == NULL) || (ud->data == NULL)) { log_err ("c_psql_write: Invalid user data."); @@ -880,7 +872,7 @@ static int c_psql_write (const data_set_t *ds, const value_list_t *vl, && (db->next_commit == 0)) c_psql_begin (db); - for (i = 0; i < db->writers_num; ++i) { + for (size_t i = 0; i < db->writers_num; ++i) { c_psql_writer_t *writer; PGresult *res; @@ -968,14 +960,13 @@ static int c_psql_flush (cdtime_t timeout, { c_psql_database_t **dbs = databases; size_t dbs_num = databases_num; - size_t i; if ((ud != NULL) && (ud->data != NULL)) { dbs = (void *)&ud->data; dbs_num = 1; } - for (i = 0; i < dbs_num; ++i) { + for (size_t i = 0; i < dbs_num; ++i) { c_psql_database_t *db = dbs[i]; /* don't commit if the timeout is larger than the regular commit @@ -989,13 +980,11 @@ static int c_psql_flush (cdtime_t timeout, static int c_psql_shutdown (void) { - size_t i = 0; - _Bool had_flush = 0; plugin_unregister_read_group ("postgresql"); - for (i = 0; i < databases_num; ++i) { + for (size_t i = 0; i < databases_num; ++i) { c_psql_database_t *db = databases[i]; if (db->writers_num > 0) { @@ -1140,7 +1129,6 @@ static int c_psql_config_writer (oconfig_item_t *ci) c_psql_writer_t *tmp; int status = 0; - int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { @@ -1163,7 +1151,7 @@ static int c_psql_config_writer (oconfig_item_t *ci) writer->statement = NULL; writer->store_rates = 1; - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *c = ci->children + i; if (strcasecmp ("Statement", c->key) == 0) @@ -1193,8 +1181,6 @@ static int c_psql_config_database (oconfig_item_t *ci) static _Bool have_flush = 0; - int i; - if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) { log_err (" expects a single string argument."); @@ -1205,7 +1191,7 @@ static int c_psql_config_database (oconfig_item_t *ci) if (db == NULL) return -1; - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *c = ci->children + i; if (0 == strcasecmp (c->key, "Host")) @@ -1242,7 +1228,7 @@ static int c_psql_config_database (oconfig_item_t *ci) /* If no `Query' options were given, add the default queries.. */ if ((db->queries_num == 0) && (db->writers_num == 0)){ - for (i = 0; i < def_queries_num; i++) + for (int i = 0; i < def_queries_num; i++) udb_query_pick_from_list_by_name (def_queries[i], queries, queries_num, &db->queries, &db->queries_num); @@ -1259,7 +1245,7 @@ static int c_psql_config_database (oconfig_item_t *ci) } } - for (i = 0; (size_t)i < db->queries_num; ++i) { + for (int i = 0; (size_t)i < db->queries_num; ++i) { c_psql_user_data_t *data; data = udb_query_get_user_data (db->queries[i]); if ((data != NULL) && (data->params_num > db->max_params_num)) @@ -1312,8 +1298,6 @@ static int c_psql_config (oconfig_item_t *ci) { static int have_def_config = 0; - int i; - if (0 == have_def_config) { oconfig_item_t *c; @@ -1330,7 +1314,7 @@ static int c_psql_config (oconfig_item_t *ci) "any queries - please check your installation."); } - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *c = ci->children + i; if (0 == strcasecmp (c->key, "Query")) diff --git a/src/powerdns.c b/src/powerdns.c index 958a3410..e215a8c3 100644 --- a/src/powerdns.c +++ b/src/powerdns.c @@ -631,8 +631,6 @@ static int powerdns_read_server (list_item_t *item) /* {{{ */ saveptr = NULL; while ((key = strtok_r (dummy, ",", &saveptr)) != NULL) { - int i; - dummy = NULL; value = strchr (key, '='); @@ -646,6 +644,7 @@ static int powerdns_read_server (list_item_t *item) /* {{{ */ continue; /* Check if this item was requested. */ + int i; for (i = 0; i < fields_num; i++) if (strcasecmp (key, fields[i]) == 0) break; @@ -781,7 +780,6 @@ static int powerdns_read_recursor (list_item_t *item) /* {{{ */ static int powerdns_config_add_collect (list_item_t *li, /* {{{ */ oconfig_item_t *ci) { - int i; char **temp; if (ci->values_num < 1) @@ -791,7 +789,7 @@ static int powerdns_config_add_collect (list_item_t *li, /* {{{ */ return (-1); } - for (i = 0; i < ci->values_num; i++) + for (int i = 0; i < ci->values_num; i++) if (ci->values[i].type != OCONFIG_TYPE_STRING) { WARNING ("powerdns plugin: Only string arguments are allowed to " @@ -808,7 +806,7 @@ static int powerdns_config_add_collect (list_item_t *li, /* {{{ */ } li->fields = temp; - for (i = 0; i < ci->values_num; i++) + for (int i = 0; i < ci->values_num; i++) { li->fields[li->fields_num] = strdup (ci->values[i].value.string); if (li->fields[li->fields_num] == NULL) @@ -831,7 +829,6 @@ static int powerdns_config_add_server (oconfig_item_t *ci) /* {{{ */ list_item_t *item; int status; - int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { @@ -880,7 +877,7 @@ static int powerdns_config_add_server (oconfig_item_t *ci) /* {{{ */ } status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; @@ -940,8 +937,6 @@ static int powerdns_config_add_server (oconfig_item_t *ci) /* {{{ */ static int powerdns_config (oconfig_item_t *ci) /* {{{ */ { - int i; - DEBUG ("powerdns plugin: powerdns_config (ci = %p);", (void *) ci); if (list == NULL) @@ -955,7 +950,7 @@ static int powerdns_config (oconfig_item_t *ci) /* {{{ */ } } - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; @@ -988,9 +983,7 @@ static int powerdns_config (oconfig_item_t *ci) /* {{{ */ static int powerdns_read (void) { - llentry_t *e; - - for (e = llist_head (list); e != NULL; e = e->next) + for (llentry_t *e = llist_head (list); e != NULL; e = e->next) { list_item_t *item = e->value; item->func (item); @@ -1001,12 +994,10 @@ static int powerdns_read (void) static int powerdns_shutdown (void) { - llentry_t *e; - if (list == NULL) return (0); - for (e = llist_head (list); e != NULL; e = e->next) + for (llentry_t *e = llist_head (list); e != NULL; e = e->next) { list_item_t *item = (list_item_t *) e->value; e->value = NULL; diff --git a/src/processes.c b/src/processes.c index b8cb192c..d34fe40f 100644 --- a/src/processes.c +++ b/src/processes.c @@ -391,13 +391,12 @@ static void ps_update_counter (_Bool init, derive_t *group_counter, /* add process entry to 'instances' of process 'name' (or refresh it) */ static void ps_list_add (const char *name, const char *cmdline, procstat_entry_t *entry) { - procstat_t *ps; procstat_entry_t *pse; if (entry->id == 0) return; - for (ps = list_head_g; ps != NULL; ps = ps->next) + for (procstat_t *ps = list_head_g; ps != NULL; ps = ps->next) { _Bool want_init; @@ -483,11 +482,10 @@ static void ps_list_add (const char *name, const char *cmdline, procstat_entry_t /* remove old entries from instances of processes in list_head_g */ static void ps_list_reset (void) { - procstat_t *ps; procstat_entry_t *pse; procstat_entry_t *pse_prev; - for (ps = list_head_g; ps != NULL; ps = ps->next) + for (procstat_t *ps = list_head_g; ps != NULL; ps = ps->next) { ps->num_proc = 0; ps->num_lwp = 0; @@ -539,15 +537,13 @@ static void ps_list_reset (void) /* put all pre-defined 'Process' names from config to list_head_g tree */ static int ps_config (oconfig_item_t *ci) { - int i; - #if KERNEL_LINUX const size_t max_procname_len = 15; #elif KERNEL_SOLARIS || KERNEL_FREEBSD const size_t max_procname_len = MAXCOMLEN -1; #endif - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *c = ci->children + i; if (strcasecmp (c->key, "Process") == 0) @@ -1468,13 +1464,12 @@ static int ps_read_process(long pid, procstat_t *ps, char *state) static int read_fork_rate (void) { extern kstat_ctl_t *kc; - kstat_t *ksp_chain = NULL; derive_t result = 0; if (kc == NULL) return (-1); - for (ksp_chain = kc->kc_chain; + for (kstat_t *ksp_chain = kc->kc_chain; ksp_chain != NULL; ksp_chain = ksp_chain->ks_next) { @@ -1540,17 +1535,14 @@ static int ps_read (void) #if HAVE_THREAD_INFO kern_return_t status; - int pset; processor_set_t port_pset_priv; - int task; task_array_t task_list; mach_msg_type_number_t task_list_len; int task_pid; char task_name[MAXCOMLEN + 1]; - int thread; thread_act_array_t thread_list; mach_msg_type_number_t thread_list_len; thread_basic_info_data_t thread_data; @@ -1575,7 +1567,7 @@ static int ps_read (void) * Tasks are assigned to sets of processors, so that's where you go to * get a list. */ - for (pset = 0; pset < pset_list_len; pset++) + for (int pset = 0; pset < pset_list_len; pset++) { if ((status = host_processor_set_priv (port_host_self, pset_list[pset], @@ -1596,7 +1588,7 @@ static int ps_read (void) continue; } - for (task = 0; task < task_list_len; task++) + for (int task = 0; task < task_list_len; task++) { ps = NULL; if (mach_get_task_name (task_list[task], @@ -1694,7 +1686,7 @@ static int ps_read (void) continue; /* with next task_list */ } - for (thread = 0; thread < thread_list_len; thread++) + for (int thread = 0; thread < thread_list_len; thread++) { thread_data_len = THREAD_BASIC_INFO_COUNT; status = thread_info (thread_list[thread], @@ -1825,8 +1817,6 @@ static int ps_read (void) procstat_entry_t pse; char state; - procstat_t *ps_ptr; - running = sleeping = zombies = stopped = paging = blocked = 0; ps_list_reset (); @@ -1907,7 +1897,7 @@ static int ps_read (void) ps_submit_state ("paging", paging); ps_submit_state ("blocked", blocked); - for (ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next) + for (procstat_t *ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next) ps_submit_proc_list (ps_ptr); read_fork_rate(); @@ -1927,9 +1917,7 @@ static int ps_read (void) struct kinfo_proc *procs; /* array of processes */ struct kinfo_proc *proc_ptr = NULL; int count; /* returns number of processes */ - int i; - procstat_t *ps_ptr; procstat_entry_t pse; ps_list_reset (); @@ -1954,7 +1942,7 @@ static int ps_read (void) } /* Iterate through the processes in kinfo_proc */ - for (i = 0; i < count; i++) + for (int i = 0; i < count; i++) { /* Create only one process list entry per _process_, i.e. * filter out threads (duplicate PID entries). */ @@ -2057,7 +2045,7 @@ static int ps_read (void) ps_submit_state ("idle", idle); ps_submit_state ("wait", wait); - for (ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next) + for (procstat_t *ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next) ps_submit_proc_list (ps_ptr); /* #endif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD */ @@ -2075,9 +2063,7 @@ static int ps_read (void) struct kinfo_proc *procs; /* array of processes */ struct kinfo_proc *proc_ptr = NULL; int count; /* returns number of processes */ - int i; - procstat_t *ps_ptr; procstat_entry_t pse; ps_list_reset (); @@ -2102,7 +2088,7 @@ static int ps_read (void) } /* Iterate through the processes in kinfo_proc */ - for (i = 0; i < count; i++) + for (int i = 0; i < count; i++) { /* Create only one process list entry per _process_, i.e. * filter out threads (duplicate PID entries). */ @@ -2194,7 +2180,7 @@ static int ps_read (void) ps_submit_state ("idle", idle); ps_submit_state ("dead", dead); - for (ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next) + for (procstat_t *ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next) ps_submit_proc_list (ps_ptr); /* #endif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_OPENBSD */ @@ -2210,7 +2196,6 @@ static int ps_read (void) pid_t pindex = 0; int nprocs; - procstat_t *ps; procstat_entry_t pse; ps_list_reset (); @@ -2218,9 +2203,7 @@ static int ps_read (void) /* fdsinfo = */ NULL, sizeof(struct fdsinfo64), &pindex, MAXPROCENTRY)) > 0) { - int i; - - for (i = 0; i < nprocs; i++) + for (int i = 0; i < nprocs; i++) { tid64_t thindex; int nthreads; @@ -2331,7 +2314,7 @@ static int ps_read (void) ps_submit_state ("paging", paging); ps_submit_state ("blocked", blocked); - for (ps = list_head_g; ps != NULL; ps = ps->next) + for (procstat_t *ps = list_head_g; ps != NULL; ps = ps->next) ps_submit_proc_list (ps); /* #endif HAVE_PROCINFO_H */ @@ -2355,7 +2338,6 @@ static int ps_read (void) DIR *proc; int status; - procstat_t *ps_ptr; char state; char cmdline[PRARGSZ]; @@ -2445,7 +2427,7 @@ static int ps_read (void) ps_submit_state ("system", system); ps_submit_state ("orphan", orphan); - for (ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next) + for (procstat_t *ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next) ps_submit_proc_list (ps_ptr); read_fork_rate(); diff --git a/src/python.c b/src/python.c index 1576057b..f5b8b93d 100644 --- a/src/python.c +++ b/src/python.c @@ -271,7 +271,7 @@ static void cpy_build_name(char *buf, size_t size, PyObject *callback, const cha } void cpy_log_exception(const char *context) { - int l = 0, i; + int l = 0; const char *typename = NULL, *message = NULL; PyObject *type, *value, *traceback, *tn, *m, *list; @@ -304,7 +304,7 @@ void cpy_log_exception(const char *context) { if (list) l = PyObject_Length(list); - for (i = 0; i < l; ++i) { + for (int i = 0; i < l; ++i) { PyObject *line; char const *msg; char *cpy; @@ -353,7 +353,6 @@ static int cpy_read_callback(user_data_t *data) { } static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_list, user_data_t *data) { - size_t i; cpy_callback_t *c = data->data; PyObject *ret, *list, *temp, *dict = NULL; Values *v; @@ -364,7 +363,7 @@ static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_li cpy_log_exception("write callback"); CPY_RETURN_FROM_THREADS 0; } - for (i = 0; i < value_list->values_len; ++i) { + for (size_t i = 0; i < value_list->values_len; ++i) { if (ds->ds[i].type == DS_TYPE_COUNTER) { PyList_SetItem(list, i, PyLong_FromUnsignedLongLong(value_list->values[i].counter)); } else if (ds->ds[i].type == DS_TYPE_GAUGE) { @@ -393,7 +392,7 @@ static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_li meta_data_t *meta = value_list->meta; num = meta_data_toc(meta, &table); - for (i = 0; i < num; ++i) { + for (size_t i = 0; i < num; ++i) { int type; char *string; int64_t si; @@ -572,7 +571,6 @@ static PyObject *float_or_none(float number) { } static PyObject *cpy_get_dataset(PyObject *self, PyObject *args) { - size_t i; char *name; const data_set_t *ds; PyObject *list, *tuple; @@ -585,7 +583,7 @@ static PyObject *cpy_get_dataset(PyObject *self, PyObject *args) { return NULL; } list = PyList_New(ds->ds_num); /* New reference. */ - for (i = 0; i < ds->ds_num; ++i) { + for (size_t i = 0; i < ds->ds_num; ++i) { tuple = PyTuple_New(4); PyTuple_SET_ITEM(tuple, 0, cpy_string_to_unicode_or_bytes(ds->ds[i].name)); PyTuple_SET_ITEM(tuple, 1, cpy_string_to_unicode_or_bytes(DS_TYPE_TO_STRING(ds->ds[i].type))); @@ -894,14 +892,13 @@ static PyMethodDef cpy_methods[] = { }; static int cpy_shutdown(void) { - cpy_callback_t *c; PyObject *ret; /* This can happen if the module was loaded but not configured. */ if (state != NULL) PyEval_RestoreThread(state); - for (c = cpy_shutdown_callbacks; c; c = c->next) { + for (cpy_callback_t *c = cpy_shutdown_callbacks; c; c = c->next) { ret = PyObject_CallFunctionObjArgs(c->callback, c->data, (void *) 0); /* New reference. */ if (ret == NULL) cpy_log_exception("shutdown callback"); @@ -966,7 +963,6 @@ static void *cpy_interactive(void *data) { } static int cpy_init(void) { - cpy_callback_t *c; PyObject *ret; static pthread_t thread; sigset_t sigset; @@ -978,7 +974,7 @@ static int cpy_init(void) { } PyEval_InitThreads(); /* Now it's finally OK to use python threads. */ - for (c = cpy_init_callbacks; c; c = c->next) { + for (cpy_callback_t *c = cpy_init_callbacks; c; c = c->next) { ret = PyObject_CallFunctionObjArgs(c->callback, c->data, (void *) 0); /* New reference. */ if (ret == NULL) cpy_log_exception("init callback"); @@ -999,14 +995,13 @@ static int cpy_init(void) { } static PyObject *cpy_oconfig_to_pyconfig(oconfig_item_t *ci, PyObject *parent) { - int i; PyObject *item, *values, *children, *tmp; if (parent == NULL) parent = Py_None; values = PyTuple_New(ci->values_num); /* New reference. */ - for (i = 0; i < ci->values_num; ++i) { + for (int i = 0; i < ci->values_num; ++i) { if (ci->values[i].type == OCONFIG_TYPE_STRING) { PyTuple_SET_ITEM(values, i, cpy_string_to_unicode_or_bytes(ci->values[i].value.string)); } else if (ci->values[i].type == OCONFIG_TYPE_NUMBER) { @@ -1021,7 +1016,7 @@ static PyObject *cpy_oconfig_to_pyconfig(oconfig_item_t *ci, PyObject *parent) { if (item == NULL) return NULL; children = PyTuple_New(ci->children_num); /* New reference. */ - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { PyTuple_SET_ITEM(children, i, cpy_oconfig_to_pyconfig(ci->children + i, item)); } tmp = ((Config *) item)->children; @@ -1108,7 +1103,6 @@ static int cpy_init_python(void) { } static int cpy_config(oconfig_item_t *ci) { - int i; PyObject *tb; /* Ok in theory we shouldn't do initialization at this point @@ -1120,7 +1114,7 @@ static int cpy_config(oconfig_item_t *ci) { if (!Py_IsInitialized() && cpy_init_python()) return 1; - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *item = ci->children + i; if (strcasecmp(item->key, "Interactive") == 0) { diff --git a/src/pyvalues.c b/src/pyvalues.c index 7cb3599d..bd2088dc 100644 --- a/src/pyvalues.c +++ b/src/pyvalues.c @@ -416,7 +416,7 @@ static int Values_init(PyObject *s, PyObject *args, PyObject *kwds) { } static meta_data_t *cpy_build_meta(PyObject *meta) { - int i, s; + int s; meta_data_t *m = NULL; PyObject *l; @@ -435,7 +435,7 @@ static meta_data_t *cpy_build_meta(PyObject *meta) { } m = meta_data_create(); - for (i = 0; i < s; ++i) { + for (int i = 0; i < s; ++i) { const char *string, *keystring; PyObject *key, *value, *item, *tmp; @@ -505,7 +505,7 @@ static meta_data_t *cpy_build_meta(PyObject *meta) { static PyObject *Values_dispatch(Values *self, PyObject *args, PyObject *kwds) { int ret; const data_set_t *ds; - size_t size, i; + size_t size; value_t *value; value_list_t value_list = VALUE_LIST_INIT; PyObject *values = self->values, *meta = self->meta; @@ -549,7 +549,7 @@ static PyObject *Values_dispatch(Values *self, PyObject *args, PyObject *kwds) { return NULL; } value = calloc(size, sizeof(*value)); - for (i = 0; i < size; ++i) { + for (size_t i = 0; i < size; ++i) { PyObject *item, *num; item = PySequence_Fast_GET_ITEM(values, (int) i); /* Borrowed reference. */ if (ds->ds->type == DS_TYPE_COUNTER) { @@ -614,7 +614,7 @@ static PyObject *Values_dispatch(Values *self, PyObject *args, PyObject *kwds) { static PyObject *Values_write(Values *self, PyObject *args, PyObject *kwds) { int ret; const data_set_t *ds; - size_t size, i; + size_t size; value_t *value; value_list_t value_list = VALUE_LIST_INIT; PyObject *values = self->values, *meta = self->meta; @@ -653,7 +653,7 @@ static PyObject *Values_write(Values *self, PyObject *args, PyObject *kwds) { return NULL; } value = calloc(size, sizeof(*value)); - for (i = 0; i < size; ++i) { + for (size_t i = 0; i < size; ++i) { PyObject *item, *num; item = PySequence_Fast_GET_ITEM(values, i); /* Borrowed reference. */ if (ds->ds->type == DS_TYPE_COUNTER) { diff --git a/src/redis.c b/src/redis.c index 5a8c7212..7395ba06 100644 --- a/src/redis.c +++ b/src/redis.c @@ -126,7 +126,6 @@ static redis_query_t *redis_config_query (oconfig_item_t *ci) /* {{{ */ { redis_query_t *rq; int status; - int i; rq = calloc(1, sizeof(*rq)); if (rq == NULL) { @@ -144,7 +143,7 @@ static redis_query_t *redis_config_query (oconfig_item_t *ci) /* {{{ */ (void)sstrncpy(rq->instance, rq->query, sizeof(rq->instance)); replace_special(rq->instance, sizeof(rq->instance)); - for (i = 0; i < ci->children_num; i++) { + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; if (strcasecmp("Type", option->key) == 0) { @@ -167,7 +166,6 @@ static redis_query_t *redis_config_query (oconfig_item_t *ci) /* {{{ */ static int redis_config_node (oconfig_item_t *ci) /* {{{ */ { redis_query_t *rq; - int i; int status; int timeout; @@ -182,7 +180,7 @@ static int redis_config_node (oconfig_item_t *ci) /* {{{ */ if (status != 0) return (status); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; @@ -230,9 +228,7 @@ static int redis_config_node (oconfig_item_t *ci) /* {{{ */ static int redis_config (oconfig_item_t *ci) /* {{{ */ { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; @@ -380,10 +376,7 @@ static int redis_handle_query (redisContext *rh, redis_node_t *rn, redis_query_t static int redis_read (void) /* {{{ */ { - redis_node_t *rn; - redis_query_t *rq; - - for (rn = nodes_head; rn != NULL; rn = rn->next) + for (redis_node_t *rn = nodes_head; rn != NULL; rn = rn->next) { redisContext *rh; redisReply *rr; @@ -442,7 +435,7 @@ static int redis_read (void) /* {{{ */ redis_handle_info (rn->name, rr->str, "total_bytes", "input", "total_net_input_bytes", DS_TYPE_DERIVE); redis_handle_info (rn->name, rr->str, "total_bytes", "output", "total_net_output_bytes", DS_TYPE_DERIVE); - for (rq = rn->queries; rq != NULL; rq = rq->next) + for (redis_query_t *rq = rn->queries; rq != NULL; rq = rq->next) redis_handle_query(rh, rn, rq); redis_fail: diff --git a/src/routeros.c b/src/routeros.c index 3cbbebc6..a270f484 100644 --- a/src/routeros.c +++ b/src/routeros.c @@ -327,7 +327,6 @@ static int cr_config_router (oconfig_item_t *ci) /* {{{ */ char read_name[128]; user_data_t user_data; int status; - int i; router_data = calloc (1, sizeof (*router_data)); if (router_data == NULL) @@ -339,7 +338,7 @@ static int cr_config_router (oconfig_item_t *ci) /* {{{ */ router_data->password = NULL; status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -424,9 +423,7 @@ static int cr_config_router (oconfig_item_t *ci) /* {{{ */ static int cr_config (oconfig_item_t *ci) { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/rrdcached.c b/src/rrdcached.c index 89367d4c..04254194 100644 --- a/src/rrdcached.c +++ b/src/rrdcached.c @@ -70,7 +70,6 @@ static int value_list_to_string (char *buffer, int buffer_len, { int offset; int status; - size_t i; time_t t; assert (0 == strcmp (ds->type, vl->type)); @@ -83,7 +82,7 @@ static int value_list_to_string (char *buffer, int buffer_len, return (-1); offset = status; - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { if ((ds->ds[i].type != DS_TYPE_COUNTER) && (ds->ds[i].type != DS_TYPE_GAUGE) @@ -218,9 +217,7 @@ static int rc_config_add_timespan (int timespan) static int rc_config (oconfig_item_t *ci) { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t const *child = ci->children + i; const char *key = child->key; @@ -294,7 +291,6 @@ static int rc_read (void) { int status; rrdc_stats_t *head; - rrdc_stats_t *ptr; value_t values[1]; value_list_t vl = VALUE_LIST_INIT; @@ -331,7 +327,7 @@ static int rc_read (void) return (-1); } - for (ptr = head; ptr != NULL; ptr = ptr->next) + for (rrdc_stats_t *ptr = head; ptr != NULL; ptr = ptr->next) { if (ptr->type == RRDC_STATS_TYPE_GAUGE) values[0].gauge = (gauge_t) ptr->value.gauge; diff --git a/src/rrdtool.c b/src/rrdtool.c index 6166ecfa..c63db52e 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -201,7 +201,6 @@ static int value_list_to_string_multiple (char *buffer, int buffer_len, int offset; int status; time_t tt; - size_t i; memset (buffer, '\0', buffer_len); @@ -211,7 +210,7 @@ static int value_list_to_string_multiple (char *buffer, int buffer_len, return (-1); offset = status; - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { if ((ds->ds[i].type != DS_TYPE_COUNTER) && (ds->ds[i].type != DS_TYPE_GAUGE) @@ -332,7 +331,6 @@ static void *rrd_queue_thread (void __attribute__((unused)) *data) char **values; int values_num; int status; - int i; values = NULL; values_num = 0; @@ -459,7 +457,7 @@ static void *rrd_queue_thread (void __attribute__((unused)) *data) values_num, (values_num == 1) ? "" : "s", queue_entry->filename); - for (i = 0; i < values_num; i++) + for (int i = 0; i < values_num; i++) { sfree (values[i]); } @@ -557,7 +555,6 @@ static void rrd_cache_flush (cdtime_t timeout) char *key; c_avl_iterator_t *iter; - int i; DEBUG ("rrdtool plugin: Flushing cache, timeout = %.3f", CDTIME_T_TO_DOUBLE (timeout)); @@ -605,7 +602,7 @@ static void rrd_cache_flush (cdtime_t timeout) } /* while (c_avl_iterator_next) */ c_avl_iterator_destroy (iter); - for (i = 0; i < keys_num; i++) + for (int i = 0; i < keys_num; i++) { if (c_avl_remove (cache, keys[i], (void *) &key, (void *) &rc) != 0) { @@ -857,7 +854,6 @@ static int rrd_cache_destroy (void) /* {{{ */ while (c_avl_pick (cache, &key, &value) == 0) { rrd_cache_t *rc; - int i; sfree (key); key = NULL; @@ -868,7 +864,7 @@ static int rrd_cache_destroy (void) /* {{{ */ if (rc->values_num > 0) non_empty++; - for (i = 0; i < rc->values_num; i++) + for (int i = 0; i < rc->values_num; i++) sfree (rc->values[i]); sfree (rc->values); sfree (rc); diff --git a/src/sensors.c b/src/sensors.c index 14dce2e3..de2a4f7b 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -216,11 +216,9 @@ static int sensors_snprintf_chip_name (char *buf, size_t buf_size, static int sensors_feature_name_to_type (const char *name) { - int i; - /* Yes, this is slow, but it's only ever done during initialization, so * it's a one time cost.. */ - for (i = 0; i < known_features_num; i++) + for (int i = 0; i < known_features_num; i++) if (strcasecmp (known_features[i].label, name) == 0) return (known_features[i].type); @@ -276,7 +274,6 @@ static int sensors_config (const char *key, const char *value) static void sensors_free_features (void) { - featurelist_t *thisft; featurelist_t *nextft; if (first_feature == NULL) @@ -284,7 +281,7 @@ static void sensors_free_features (void) sensors_cleanup (); - for (thisft = first_feature; thisft != NULL; thisft = nextft) + for (featurelist_t *thisft = first_feature; thisft != NULL; thisft = nextft) { nextft = thisft->next; sfree (thisft); @@ -522,13 +519,11 @@ static void sensors_submit (const char *plugin_instance, static int sensors_read (void) { - featurelist_t *fl; - if (sensors_load_conf () != 0) return (-1); #if SENSORS_API_VERSION < 0x400 - for (fl = first_feature; fl != NULL; fl = fl->next) + for (featurelist_t *fl = first_feature; fl != NULL; fl = fl->next) { double value; int status; @@ -556,7 +551,7 @@ static int sensors_read (void) /* #endif SENSORS_API_VERSION < 0x400 */ #elif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500) - for (fl = first_feature; fl != NULL; fl = fl->next) + for (featurelist_t *fl = first_feature; fl != NULL; fl = fl->next) { double value; int status; diff --git a/src/serial.c b/src/serial.c index 3f7e92d0..cf7ad2a1 100644 --- a/src/serial.c +++ b/src/serial.c @@ -74,7 +74,6 @@ static int serial_read (void) char *fields[16]; int numfields; - int i; numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields)); if (numfields < 6) @@ -91,7 +90,7 @@ static int serial_read (void) continue; fields[0][len - 1] = 0; - for (i = 1; i < numfields; i++) + for (int i = 1; i < numfields; i++) { len = strlen (fields[i]); if (len < 4) diff --git a/src/sigrok.c b/src/sigrok.c index e7aab7f3..40064553 100644 --- a/src/sigrok.c +++ b/src/sigrok.c @@ -70,7 +70,6 @@ static int sigrok_log_callback(void*cb_data __attribute__((unused)), static int sigrok_config_device(oconfig_item_t *ci) { struct config_device *cfdev; - int i; if (!(cfdev = calloc(1, sizeof(*cfdev)))) { ERROR("sigrok plugin: calloc failed."); @@ -83,7 +82,7 @@ static int sigrok_config_device(oconfig_item_t *ci) } cfdev->min_dispatch_interval = DEFAULT_MIN_DISPATCH_INTERVAL; - for (i = 0; i < ci->children_num; i++) { + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *item = ci->children + i; if (!strcasecmp(item->key, "driver")) cf_util_get_string(item, &cfdev->driver); @@ -105,9 +104,7 @@ static int sigrok_config_device(oconfig_item_t *ci) static int sigrok_config(oconfig_item_t *ci) { - int i; - - for (i = 0; i < ci->children_num; i++) { + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *item = ci->children + i; if (strcasecmp("LogLevel", item->key) == 0) { int status; @@ -164,13 +161,12 @@ static void sigrok_feed_callback(const struct sr_dev_inst *sdi, { const struct sr_datafeed_analog *analog; struct config_device *cfdev; - GSList *l; value_t value; value_list_t vl = VALUE_LIST_INIT; /* Find this device's configuration. */ cfdev = NULL; - for (l = config_devices; l; l = l->next) { + for (GSList *l = config_devices; l; l = l->next) { cfdev = l->data; if (cfdev->sdi == sdi) { /* Found it. */ diff --git a/src/snmp.c b/src/snmp.c index 60bec83c..8b327308 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -165,9 +165,8 @@ static int csnmp_oid_to_string (char *buffer, size_t buffer_size, { char oid_str[MAX_OID_LEN][16]; char *oid_str_ptr[MAX_OID_LEN]; - size_t i; - for (i = 0; i < o->oid_len; i++) + for (size_t i = 0; i < o->oid_len; i++) { ssnprintf (oid_str[i], sizeof (oid_str[i]), "%lu", (unsigned long) o->oid[i]); oid_str_ptr[i] = oid_str[i]; @@ -292,15 +291,13 @@ static int csnmp_config_add_data_instance_prefix (data_definition_t *dd, static int csnmp_config_add_data_values (data_definition_t *dd, oconfig_item_t *ci) { - int i; - if (ci->values_num < 1) { WARNING ("snmp plugin: `Values' needs at least one argument."); return (-1); } - for (i = 0; i < ci->values_num; i++) + for (int i = 0; i < ci->values_num; i++) if (ci->values[i].type != OCONFIG_TYPE_STRING) { WARNING ("snmp plugin: `Values' needs only string argument."); @@ -314,7 +311,7 @@ static int csnmp_config_add_data_values (data_definition_t *dd, oconfig_item_t * return (-1); dd->values_len = (size_t) ci->values_num; - for (i = 0; i < ci->values_num; i++) + for (int i = 0; i < ci->values_num; i++) { dd->values[i].oid_len = MAX_OID_LEN; @@ -335,12 +332,10 @@ static int csnmp_config_add_data_values (data_definition_t *dd, oconfig_item_t * static int csnmp_config_add_data_blacklist(data_definition_t *dd, oconfig_item_t *ci) { - int i; - if (ci->values_num < 1) return (0); - for (i = 0; i < ci->values_num; i++) + for (int i = 0; i < ci->values_num; i++) { if (ci->values[i].type != OCONFIG_TYPE_STRING) { @@ -352,7 +347,7 @@ static int csnmp_config_add_data_blacklist(data_definition_t *dd, oconfig_item_t dd->ignores_len = 0; dd->ignores = NULL; - for (i = 0; i < ci->values_num; ++i) + for (int i = 0; i < ci->values_num; ++i) { if (strarray_add(&(dd->ignores), &(dd->ignores_len), ci->values[i].value.string) != 0) { @@ -381,7 +376,6 @@ static int csnmp_config_add_data (oconfig_item_t *ci) { data_definition_t *dd; int status = 0; - int i; dd = calloc (1, sizeof (*dd)); if (dd == NULL) @@ -397,7 +391,7 @@ static int csnmp_config_add_data (oconfig_item_t *ci) dd->scale = 1.0; dd->shift = 0.0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; @@ -503,7 +497,6 @@ static int csnmp_config_add_host_collect (host_definition_t *host, data_definition_t *data; data_definition_t **data_list; int data_list_len; - int i; if (ci->values_num < 1) { @@ -511,7 +504,7 @@ static int csnmp_config_add_host_collect (host_definition_t *host, return (-1); } - for (i = 0; i < ci->values_num; i++) + for (int i = 0; i < ci->values_num; i++) if (ci->values[i].type != OCONFIG_TYPE_STRING) { WARNING ("snmp plugin: All arguments to `Collect' must be strings."); @@ -525,7 +518,7 @@ static int csnmp_config_add_host_collect (host_definition_t *host, return (-1); host->data_list = data_list; - for (i = 0; i < ci->values_num; i++) + for (int i = 0; i < ci->values_num; i++) { for (data = data_head; data != NULL; data = data->next) if (strcasecmp (ci->values[i].value.string, data->name) == 0) @@ -638,7 +631,6 @@ static int csnmp_config_add_host (oconfig_item_t *ci) { host_definition_t *hd; int status = 0; - int i; /* Registration stuff. */ char cb_name[DATA_MAX_NAME_LEN]; @@ -660,7 +652,7 @@ static int csnmp_config_add_host (oconfig_item_t *ci) hd->sess_handle = NULL; hd->interval = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; status = 0; @@ -790,11 +782,9 @@ static int csnmp_config_add_host (oconfig_item_t *ci) static int csnmp_config (oconfig_item_t *ci) { - int i; - call_snmp_init_once (); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Data", child->key) == 0) @@ -1055,14 +1045,13 @@ static int csnmp_strvbcopy_hexstring (char *dst, /* {{{ */ { char *buffer_ptr; size_t buffer_free; - size_t i; dst[0] = 0; buffer_ptr = dst; buffer_free = dst_size; - for (i = 0; i < vb->val_len; i++) + for (size_t i = 0; i < vb->val_len; i++) { int status; @@ -1095,7 +1084,6 @@ static int csnmp_strvbcopy (char *dst, /* {{{ */ { char *src; size_t num_chars; - size_t i; if (vb->type == ASN_OCTET_STR) src = (char *) vb->val.string; @@ -1119,7 +1107,7 @@ static int csnmp_strvbcopy (char *dst, /* {{{ */ if (num_chars > vb->val_len) num_chars = vb->val_len; - for (i = 0; i < num_chars; i++) + for (size_t i = 0; i < num_chars; i++) { /* Check for control characters. */ if ((unsigned char)src[i] < 32) @@ -1144,7 +1132,6 @@ static int csnmp_instance_list_add (csnmp_list_instances_t **head, struct variable_list *vb; oid_t vb_name; int status; - uint32_t i; uint32_t is_matched; /* Set vb on the last variable */ @@ -1179,7 +1166,7 @@ static int csnmp_instance_list_add (csnmp_list_instances_t **head, csnmp_strvbcopy (il->instance, vb, sizeof (il->instance)); is_matched = 0; - for (i = 0; i < dd->ignores_len; i++) + for (uint32_t i = 0; i < dd->ignores_len; i++) { status = fnmatch(dd->ignores[i], il->instance, 0); if (status == 0) diff --git a/src/statsd.c b/src/statsd.c index 7eb58622..040181aa 100644 --- a/src/statsd.c +++ b/src/statsd.c @@ -502,7 +502,6 @@ static int statsd_network_init (struct pollfd **ret_fds, /* {{{ */ size_t fds_num = 0; struct addrinfo *ai_list; - struct addrinfo *ai_ptr; int status; char const *node = (conf_node != NULL) ? conf_node : STATSD_DEFAULT_NODE; @@ -523,7 +522,7 @@ static int statsd_network_init (struct pollfd **ret_fds, /* {{{ */ return (status); } - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { int fd; struct pollfd *tmp; @@ -590,7 +589,6 @@ static void *statsd_network_thread (void *args) /* {{{ */ struct pollfd *fds = NULL; size_t fds_num = 0; int status; - size_t i; status = statsd_network_init (&fds, &fds_num); if (status != 0) @@ -614,7 +612,7 @@ static void *statsd_network_thread (void *args) /* {{{ */ break; } - for (i = 0; i < fds_num; i++) + for (size_t i = 0; i < fds_num; i++) { if ((fds[i].revents & (POLLIN | POLLPRI)) == 0) continue; @@ -625,7 +623,7 @@ static void *statsd_network_thread (void *args) /* {{{ */ } /* while (!network_thread_shutdown) */ /* Clean up */ - for (i = 0; i < fds_num; i++) + for (size_t i = 0; i < fds_num; i++) close (fds[i].fd); sfree (fds); @@ -665,9 +663,7 @@ static int statsd_config_timer_percentile (oconfig_item_t *ci) /* {{{ */ static int statsd_config (oconfig_item_t *ci) /* {{{ */ { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -780,7 +776,6 @@ static int statsd_metric_submit_unsafe (char const *name, statsd_metric_t *metri values[0].gauge = (gauge_t) metric->value; else if (metric->type == STATSD_TIMER) { - size_t i; _Bool have_events = (metric->updates_num > 0); /* Make sure all timer metrics share the *same* timestamp. */ @@ -820,7 +815,7 @@ static int statsd_metric_submit_unsafe (char const *name, statsd_metric_t *metri plugin_dispatch_values (&vl); } - for (i = 0; i < conf_timer_percentile_num; i++) + for (size_t i = 0; i < conf_timer_percentile_num; i++) { ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%s-percentile-%.0f", name, conf_timer_percentile[i]); @@ -886,7 +881,6 @@ static int statsd_read (void) /* {{{ */ char **to_be_deleted = NULL; size_t to_be_deleted_num = 0; - size_t i; pthread_mutex_lock (&metrics_lock); @@ -921,7 +915,7 @@ static int statsd_read (void) /* {{{ */ } c_avl_iterator_destroy (iter); - for (i = 0; i < to_be_deleted_num; i++) + for (size_t i = 0; i < to_be_deleted_num; i++) { int status; diff --git a/src/swap.c b/src/swap.c index 32906fa8..15eca9aa 100644 --- a/src/swap.c +++ b/src/swap.c @@ -113,9 +113,7 @@ static _Bool values_percentage = 0; static int swap_config (oconfig_item_t *ci) /* {{{ */ { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("ReportBytes", child->key) == 0) @@ -510,7 +508,6 @@ static int swap_read (void) /* {{{ */ char *s_paths; int swap_num; int status; - int i; gauge_t avail = 0; gauge_t total = 0; @@ -543,7 +540,7 @@ static int swap_read (void) /* {{{ */ sfree (s); return (-1); } - for (i = 0; i < swap_num; i++) + for (int i = 0; i < swap_num; i++) s->swt_ent[i].ste_path = s_paths + (i * PATH_MAX); s->swt_n = swap_num; @@ -573,7 +570,7 @@ static int swap_read (void) /* {{{ */ /* less elements returned than requested */ swap_num = status; - for (i = 0; i < swap_num; i++) + for (int i = 0; i < swap_num; i++) { char path[PATH_MAX]; gauge_t this_total; @@ -626,7 +623,6 @@ static int swap_read (void) /* {{{ */ struct swapent *swap_entries; int swap_num; int status; - int i; gauge_t used = 0; gauge_t total = 0; @@ -665,7 +661,7 @@ static int swap_read (void) /* {{{ */ /* TODO: Report per-device stats. The path name is available from * swap_entries[i].se_path */ - for (i = 0; i < swap_num; i++) + for (int i = 0; i < swap_num; i++) { if ((swap_entries[i].se_flags & SWF_ENABLE) == 0) continue; diff --git a/src/table.c b/src/table.c index d2c4249f..ba65f41c 100644 --- a/src/table.c +++ b/src/table.c @@ -106,13 +106,11 @@ static void tbl_setup (tbl_t *tbl, char *file) static void tbl_clear (tbl_t *tbl) { - size_t i; - sfree (tbl->file); sfree (tbl->sep); sfree (tbl->instance); - for (i = 0; i < tbl->results_num; ++i) + for (size_t i = 0; i < tbl->results_num; ++i) tbl_result_clear (tbl->results + i); sfree (tbl->results); tbl->results_num = 0; @@ -145,7 +143,6 @@ static int tbl_config_append_array_i (char *name, size_t **var, size_t *len, { size_t *tmp; size_t num; - size_t i; if (1 > ci->values_num) { log_err ("\"%s\" expects at least one argument.", name); @@ -153,7 +150,7 @@ static int tbl_config_append_array_i (char *name, size_t **var, size_t *len, } num = (size_t) ci->values_num; - for (i = 0; i < num; ++i) { + for (size_t i = 0; i < num; ++i) { if (OCONFIG_TYPE_NUMBER != ci->values[i].type) { log_err ("\"%s\" expects numerical arguments only.", name); return 1; @@ -169,7 +166,7 @@ static int tbl_config_append_array_i (char *name, size_t **var, size_t *len, } *var = tmp; - for (i = 0; i < num; ++i) { + for (size_t i = 0; i < num; ++i) { (*var)[*len] = (size_t) ci->values[i].value.number; (*len)++; } @@ -182,7 +179,6 @@ static int tbl_config_result (tbl_t *tbl, oconfig_item_t *ci) tbl_result_t *res; int status = 0; - int i; if (0 != ci->values_num) { log_err (" does not expect any arguments."); @@ -204,7 +200,7 @@ static int tbl_config_result (tbl_t *tbl, oconfig_item_t *ci) res = tbl->results + tbl->results_num - 1; tbl_result_setup (res); - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *c = ci->children + i; if (0 == strcasecmp (c->key, "Type")) @@ -247,7 +243,6 @@ static int tbl_config_table (oconfig_item_t *ci) tbl_t *tbl; int status = 0; - size_t i; if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) { @@ -269,7 +264,7 @@ static int tbl_config_table (oconfig_item_t *ci) tbl = tables + tables_num - 1; tbl_setup (tbl, ci->values[0].value.string); - for (i = 0; i < ((size_t) ci->children_num); ++i) { + for (size_t i = 0; i < ((size_t) ci->children_num); ++i) { oconfig_item_t *c = ci->children + i; if (0 == strcasecmp (c->key, "Separator")) @@ -307,15 +302,14 @@ static int tbl_config_table (oconfig_item_t *ci) return status; } - for (i = 0; i < tbl->results_num; ++i) { + for (size_t i = 0; i < tbl->results_num; ++i) { tbl_result_t *res = tbl->results + i; - size_t j; - for (j = 0; j < res->instances_num; ++j) + for (size_t j = 0; j < res->instances_num; ++j) if (res->instances[j] > tbl->max_colnum) tbl->max_colnum = res->instances[j]; - for (j = 0; j < res->values_num; ++j) + for (size_t j = 0; j < res->values_num; ++j) if (res->values[j] > tbl->max_colnum) tbl->max_colnum = res->values[j]; } @@ -324,9 +318,7 @@ static int tbl_config_table (oconfig_item_t *ci) static int tbl_config (oconfig_item_t *ci) { - int i; - - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *c = ci->children + i; if (0 == strcasecmp (c->key, "Table")) @@ -343,9 +335,7 @@ static int tbl_config (oconfig_item_t *ci) static int tbl_prepare (tbl_t *tbl) { - size_t i; - - for (i = 0; i < tbl->results_num; ++i) { + for (size_t i = 0; i < tbl->results_num; ++i) { tbl_result_t *res = tbl->results + i; res->ds = plugin_get_ds (res->type); @@ -368,9 +358,7 @@ static int tbl_prepare (tbl_t *tbl) static int tbl_finish (tbl_t *tbl) { - size_t i; - - for (i = 0; i < tbl->results_num; ++i) + for (size_t i = 0; i < tbl->results_num; ++i) tbl->results[i].ds = NULL; return 0; } /* tbl_finish */ @@ -381,12 +369,10 @@ static int tbl_result_dispatch (tbl_t *tbl, tbl_result_t *res, value_list_t vl = VALUE_LIST_INIT; value_t values[res->values_num]; - size_t i; - assert (NULL != res->ds); assert (res->values_num == res->ds->ds_num); - for (i = 0; i < res->values_num; ++i) { + for (size_t i = 0; i < res->values_num; ++i) { char *value; assert (res->values[i] < fields_num); @@ -413,7 +399,7 @@ static int tbl_result_dispatch (tbl_t *tbl, tbl_result_t *res, char *instances[res->instances_num]; char instances_str[DATA_MAX_NAME_LEN]; - for (i = 0; i < res->instances_num; ++i) { + for (size_t i = 0; i < res->instances_num; ++i) { assert (res->instances[i] < fields_num); instances[i] = fields[res->instances[i]]; } @@ -445,9 +431,8 @@ static int tbl_parse_line (tbl_t *tbl, char *line, size_t len) char *fields[tbl->max_colnum + 1]; char *ptr, *saveptr; - size_t i; + size_t i = 0; - i = 0; ptr = line; saveptr = NULL; while (NULL != (fields[i] = strtok_r (ptr, tbl->sep, &saveptr))) { @@ -519,12 +504,11 @@ static int tbl_read_table (tbl_t *tbl) static int tbl_read (void) { int status = -1; - size_t i; if (0 == tables_num) return 0; - for (i = 0; i < tables_num; ++i) { + for (size_t i = 0; i < tables_num; ++i) { tbl_t *tbl = tables + i; if (0 != tbl_prepare (tbl)) { @@ -542,9 +526,7 @@ static int tbl_read (void) static int tbl_shutdown (void) { - size_t i; - - for (i = 0; i < tables_num; ++i) + for (size_t i = 0; i < tables_num; ++i) tbl_clear (&tables[i]); sfree (tables); return 0; diff --git a/src/tail.c b/src/tail.c index 732607cf..b8922ecb 100644 --- a/src/tail.c +++ b/src/tail.c @@ -140,7 +140,6 @@ static int ctail_config_add_match (cu_tail_match_t *tm, { ctail_config_match_t cm = { 0 }; int status; - int i; if (ci->values_num != 0) { @@ -148,7 +147,7 @@ static int ctail_config_add_match (cu_tail_match_t *tm, } status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; @@ -223,7 +222,6 @@ static int ctail_config_add_file (oconfig_item_t *ci) cdtime_t interval = 0; char *plugin_instance = NULL; int num_matches = 0; - int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { @@ -239,7 +237,7 @@ static int ctail_config_add_file (oconfig_item_t *ci) return (-1); } - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; int status = 0; @@ -298,9 +296,7 @@ static int ctail_config_add_file (oconfig_item_t *ci) static int ctail_config (oconfig_item_t *ci) { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; @@ -333,7 +329,6 @@ static int ctail_init (void) { char str[255]; user_data_t ud = { 0 }; - size_t i; if (tail_match_list_num == 0) { @@ -341,7 +336,7 @@ static int ctail_init (void) return (-1); } - for (i = 0; i < tail_match_list_num; i++) + for (size_t i = 0; i < tail_match_list_num; i++) { ud.data = (void *)tail_match_list[i]; ssnprintf(str, sizeof(str), "tail-%zu", i); @@ -353,9 +348,7 @@ static int ctail_init (void) static int ctail_shutdown (void) { - size_t i; - - for (i = 0; i < tail_match_list_num; i++) + for (size_t i = 0; i < tail_match_list_num; i++) { tail_match_destroy (tail_match_list[i]); tail_match_list[i] = NULL; diff --git a/src/tail_csv.c b/src/tail_csv.c index 86c4fa88..79ea4665 100644 --- a/src/tail_csv.c +++ b/src/tail_csv.c @@ -289,7 +289,6 @@ static int tcsv_config_get_index(oconfig_item_t *ci, ssize_t *ret_index) { static int tcsv_config_add_metric(oconfig_item_t *ci){ metric_definition_t *md; int status; - int i; md = calloc(1, sizeof(*md)); if (md == NULL) @@ -307,7 +306,7 @@ static int tcsv_config_add_metric(oconfig_item_t *ci){ return (-1); } - for (i = 0; i < ci->children_num; ++i){ + for (int i = 0; i < ci->children_num; ++i){ oconfig_item_t *option = ci->children + i; if (strcasecmp("Type", option->key) == 0) @@ -377,7 +376,6 @@ static int tcsv_config_add_instance_collect(instance_definition_t *id, oconfig_i metric_definition_t *metric; metric_definition_t **metric_list; size_t metric_list_size; - int i; if (ci->values_num < 1) { WARNING("tail_csv plugin: The `Collect' config option needs at least one argument."); @@ -390,7 +388,7 @@ static int tcsv_config_add_instance_collect(instance_definition_t *id, oconfig_i return (-1); id->metric_list = metric_list; - for (i = 0; i < ci->values_num; i++) { + for (int i = 0; i < ci->values_num; i++) { char *metric_name; if (ci->values[i].type != OCONFIG_TYPE_STRING) { @@ -420,7 +418,6 @@ static int tcsv_config_add_file(oconfig_item_t *ci) { instance_definition_t* id; int status = 0; - int i; /* Registration variables */ char cb_name[DATA_MAX_NAME_LEN]; @@ -444,7 +441,7 @@ static int tcsv_config_add_file(oconfig_item_t *ci) /* Use default interval. */ id->interval = plugin_get_interval(); - for (i = 0; i < ci->children_num; ++i){ + for (int i = 0; i < ci->children_num; ++i){ oconfig_item_t *option = ci->children + i; status = 0; @@ -500,8 +497,7 @@ static int tcsv_config_add_file(oconfig_item_t *ci) /* Parse blocks */ static int tcsv_config(oconfig_item_t *ci){ - int i; - for (i = 0; i < ci->children_num; ++i){ + for (int i = 0; i < ci->children_num; ++i){ oconfig_item_t *child = ci->children + i; if (strcasecmp("Metric", child->key) == 0) tcsv_config_add_metric(child); diff --git a/src/tape.c b/src/tape.c index 723ee7b8..52da2bc6 100644 --- a/src/tape.c +++ b/src/tape.c @@ -99,7 +99,6 @@ static int tape_read (void) # error "kstat_io_t does not have the required members" #endif static kstat_io_t kio; - int i; if (kc == NULL) return (-1); @@ -107,7 +106,7 @@ static int tape_read (void) if (numtape <= 0) return (-1); - for (i = 0; i < numtape; i++) + for (int i = 0; i < numtape; i++) { if (kstat_read (kc, ksp[i], &kio) == -1) continue; diff --git a/src/target_notification.c b/src/target_notification.c index 59d8c94f..21c071ed 100644 --- a/src/target_notification.c +++ b/src/target_notification.c @@ -125,7 +125,6 @@ static int tn_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ { tn_data_t *data; int status; - int i; data = calloc (1, sizeof (*data)); if (data == NULL) @@ -138,7 +137,7 @@ static int tn_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ data->severity = 0; status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -199,8 +198,6 @@ static int tn_invoke (const data_set_t *ds, value_list_t *vl, /* {{{ */ gauge_t *rates; int rates_failed; - size_t i; - if ((ds == NULL) || (vl == NULL) || (user_data == NULL)) return (-EINVAL); @@ -235,7 +232,8 @@ static int tn_invoke (const data_set_t *ds, value_list_t *vl, /* {{{ */ rates_failed = 0; rates = NULL; - for (i = 0; i < ds->ds_num; i++) + + for (size_t i = 0; i < ds->ds_num; i++) { char template[DATA_MAX_NAME_LEN]; char value_str[DATA_MAX_NAME_LEN]; diff --git a/src/target_replace.c b/src/target_replace.c index 8389ce3f..40a6fec9 100644 --- a/src/target_replace.c +++ b/src/target_replace.c @@ -156,7 +156,6 @@ static int tr_config_add_action (tr_action_t **dest, /* {{{ */ static int tr_action_invoke (tr_action_t *act_head, /* {{{ */ char *buffer_in, size_t buffer_in_size, int may_be_empty) { - tr_action_t *act; int status; char buffer[DATA_MAX_NAME_LEN]; regmatch_t matches[8] = { [0] = { 0 } }; @@ -168,7 +167,7 @@ static int tr_action_invoke (tr_action_t *act_head, /* {{{ */ DEBUG ("target_replace plugin: tr_action_invoke: <- buffer = %s;", buffer); - for (act = act_head; act != NULL; act = act->next) + for (tr_action_t *act = act_head; act != NULL; act = act->next) { char temp[DATA_MAX_NAME_LEN]; char *subst_status; @@ -241,7 +240,6 @@ static int tr_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ { tr_data_t *data; int status; - int i; data = calloc (1, sizeof (*data)); if (data == NULL) @@ -257,7 +255,7 @@ static int tr_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ data->type_instance = NULL; status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/target_scale.c b/src/target_scale.c index 8659c8d7..22af4e31 100644 --- a/src/target_scale.c +++ b/src/target_scale.c @@ -303,7 +303,6 @@ static int ts_config_add_data_source(ts_data_t *data, /* {{{ */ { size_t new_data_sources_num; char **temp; - int i; /* Check number of arbuments. */ if (ci->values_num < 1) @@ -314,7 +313,7 @@ static int ts_config_add_data_source(ts_data_t *data, /* {{{ */ } /* Check type of arguments */ - for (i = 0; i < ci->values_num; i++) + for (int i = 0; i < ci->values_num; i++) { if (ci->values[i].type == OCONFIG_TYPE_STRING) continue; @@ -339,7 +338,7 @@ static int ts_config_add_data_source(ts_data_t *data, /* {{{ */ data->data_sources = temp; /* Copy the strings, allocating memory as needed. */ - for (i = 0; i < ci->values_num; i++) + for (int i = 0; i < ci->values_num; i++) { size_t j; @@ -370,8 +369,7 @@ static int ts_destroy (void **user_data) /* {{{ */ if ((data != NULL) && (data->data_sources != NULL)) { - size_t i; - for (i = 0; i < data->data_sources_num; i++) + for (size_t i = 0; i < data->data_sources_num; i++) sfree (data->data_sources[i]); sfree (data->data_sources); } @@ -386,7 +384,6 @@ static int ts_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ { ts_data_t *data; int status; - int i; data = calloc (1, sizeof (*data)); if (data == NULL) @@ -399,7 +396,7 @@ static int ts_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ data->offset = NAN; status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -447,7 +444,6 @@ static int ts_invoke (const data_set_t *ds, value_list_t *vl, /* {{{ */ notification_meta_t __attribute__((unused)) **meta, void **user_data) { ts_data_t *data; - size_t i; if ((ds == NULL) || (vl == NULL) || (user_data == NULL)) return (-EINVAL); @@ -459,7 +455,7 @@ static int ts_invoke (const data_set_t *ds, value_list_t *vl, /* {{{ */ return (-EINVAL); } - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { /* If we've got a list of data sources, is it in the list? */ if (data->data_sources) { diff --git a/src/target_set.c b/src/target_set.c index ee068ec3..fee5ffdc 100644 --- a/src/target_set.c +++ b/src/target_set.c @@ -143,7 +143,6 @@ static int ts_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ { ts_data_t *data; int status; - int i; data = calloc (1, sizeof (*data)); if (data == NULL) @@ -160,7 +159,7 @@ static int ts_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ data->meta = NULL; status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/tcpconns.c b/src/tcpconns.c index e28a8694..e74e4bc8 100644 --- a/src/tcpconns.c +++ b/src/tcpconns.c @@ -305,7 +305,6 @@ static void conn_submit_port_entry (port_entry_t *pe) { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - int i; conn_prepare_vl (&vl, values); @@ -315,7 +314,7 @@ static void conn_submit_port_entry (port_entry_t *pe) ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "%"PRIu16"-local", pe->port); - for (i = 1; i <= TCP_STATE_MAX; i++) + for (int i = 1; i <= TCP_STATE_MAX; i++) { vl.values[0].gauge = pe->count_local[i]; @@ -330,7 +329,7 @@ static void conn_submit_port_entry (port_entry_t *pe) ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "%"PRIu16"-remote", pe->port); - for (i = 1; i <= TCP_STATE_MAX; i++) + for (int i = 1; i <= TCP_STATE_MAX; i++) { vl.values[0].gauge = pe->count_remote[i]; @@ -345,13 +344,12 @@ static void conn_submit_port_total (void) { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - int i; conn_prepare_vl (&vl, values); sstrncpy (vl.plugin_instance, "all", sizeof (vl.plugin_instance)); - for (i = 1; i <= TCP_STATE_MAX; i++) + for (int i = 1; i <= TCP_STATE_MAX; i++) { vl.values[0].gauge = count_total[i]; @@ -363,12 +361,10 @@ static void conn_submit_port_total (void) static void conn_submit_all (void) { - port_entry_t *pe; - if (port_collect_total) conn_submit_port_total (); - for (pe = port_list_head; pe != NULL; pe = pe->next) + for (port_entry_t *pe = port_list_head; pe != NULL; pe = pe->next) conn_submit_port_entry (pe); } /* void conn_submit_all */ @@ -1017,7 +1013,6 @@ static int conn_read (void) static int conn_read (void) { int size; - int i; int nconn; void *data; struct netinfo_header *header; @@ -1059,7 +1054,7 @@ static int conn_read (void) nconn = header->size; conn = (struct netinfo_conn *)(data + sizeof(struct netinfo_header)); - for (i=0; i < nconn; conn++, i++) + for (int i = 0; i < nconn; conn++, i++) { conn_handle_ports (conn->srcport, conn->dstport, conn->tcp_state); } diff --git a/src/teamspeak2.c b/src/teamspeak2.c index 40ca15e6..a1cde320 100644 --- a/src/teamspeak2.c +++ b/src/teamspeak2.c @@ -200,7 +200,6 @@ static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh) * if it's not already present */ struct addrinfo *ai_head; - struct addrinfo *ai_ptr; int sd = -1; int status; @@ -234,7 +233,7 @@ static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh) } /* Try all given hosts until we can connect to one */ - for (ai_ptr = ai_head; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_head; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { /* Create socket */ sd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, @@ -770,7 +769,6 @@ static int tss2_read (void) * Poll function which collects global and vserver information * and submits it to collectd */ - vserver_list_t *vserver; int success = 0; int status; @@ -786,7 +784,7 @@ static int tss2_read (void) } /* Handle vservers */ - for (vserver = server_list; vserver != NULL; vserver = vserver->next) + for (vserver_list_t *vserver = server_list; vserver != NULL; vserver = vserver->next) { status = tss2_read_vserver (vserver); if (status == 0) diff --git a/src/ted.c b/src/ted.c index 28ee8e48..96c94e5d 100644 --- a/src/ted.c +++ b/src/ted.c @@ -108,7 +108,6 @@ static int ted_read_value(double *ret_power, double *ret_voltage) while (end_flag == 0) { ssize_t receive_buffer_length; - ssize_t i; /* check for timeout or input error*/ status = select (fd + 1, &input, NULL, NULL, &timeout); @@ -165,7 +164,7 @@ static int ted_read_value(double *ret_power, double *ret_voltage) * the beginning of the package has been found. */ escape_flag = 0; - for (i = 0; i < receive_buffer_length; i++) + for (ssize_t i = 0; i < receive_buffer_length; i++) { /* Check if previous byte was the escape byte. */ if (escape_flag == 1) @@ -312,7 +311,6 @@ static int ted_read (void) double power; double voltage; int status; - int i; status = ted_open_device (); if (status != 0) @@ -320,7 +318,7 @@ static int ted_read (void) power = NAN; voltage = NAN; - for (i = 0; i <= conf_retries; i++) + for (int i = 0; i <= conf_retries; i++) { status = ted_read_value (&power, &voltage); if (status == 0) diff --git a/src/threshold.c b/src/threshold.c index bbd40913..1d9bcf95 100644 --- a/src/threshold.c +++ b/src/threshold.c @@ -216,7 +216,6 @@ static int ut_config_type_hysteresis (threshold_t *th, oconfig_item_t *ci) static int ut_config_type (const threshold_t *th_orig, oconfig_item_t *ci) { - int i; threshold_t th; int status = 0; @@ -245,7 +244,7 @@ static int ut_config_type (const threshold_t *th_orig, oconfig_item_t *ci) th.hysteresis = 0; th.flags = UT_FLAG_INTERESTING; /* interesting by default */ - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; @@ -310,7 +309,6 @@ static int ut_config_plugin_instance (threshold_t *th, oconfig_item_t *ci) static int ut_config_plugin (const threshold_t *th_orig, oconfig_item_t *ci) { - int i; threshold_t th; int status = 0; @@ -332,7 +330,7 @@ static int ut_config_plugin (const threshold_t *th_orig, oconfig_item_t *ci) memcpy (&th, th_orig, sizeof (th)); sstrncpy (th.plugin, ci->values[0].value.string, sizeof (th.plugin)); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; @@ -356,7 +354,6 @@ static int ut_config_plugin (const threshold_t *th_orig, oconfig_item_t *ci) static int ut_config_host (const threshold_t *th_orig, oconfig_item_t *ci) { - int i; threshold_t th; int status = 0; @@ -378,7 +375,7 @@ static int ut_config_host (const threshold_t *th_orig, oconfig_item_t *ci) memcpy (&th, th_orig, sizeof (th)); sstrncpy (th.host, ci->values[0].value.string, sizeof (th.host)); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; @@ -550,10 +547,9 @@ static int ut_report_state (const data_set_t *ds, { gauge_t value; gauge_t sum; - size_t i; sum = 0.0; - for (i = 0; i < vl->values_len; i++) + for (size_t i = 0; i < vl->values_len; i++) { if (isnan (values[i])) continue; @@ -698,7 +694,6 @@ static int ut_check_one_threshold (const data_set_t *ds, { /* {{{ */ int ret = -1; int ds_index = -1; - size_t i; gauge_t values_copy[ds->ds_num]; memcpy (values_copy, values, sizeof (values_copy)); @@ -717,7 +712,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++; @@ -727,17 +722,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++) { int status; @@ -867,7 +862,6 @@ static int ut_missing (const value_list_t *vl, static int ut_config (oconfig_item_t *ci) { /* {{{ */ - int i; int status = 0; int old_size = c_avl_size (threshold_tree); @@ -889,7 +883,7 @@ static int ut_config (oconfig_item_t *ci) .flags = UT_FLAG_INTERESTING /* interesting by default */ }; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; diff --git a/src/turbostat.c b/src/turbostat.c index 2b3ce0ef..913511f7 100644 --- a/src/turbostat.c +++ b/src/turbostat.c @@ -652,11 +652,10 @@ for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_dat struct thread_data *thread_base, struct core_data *core_base, struct pkg_data *pkg_base) { int retval; - unsigned int pkg_no, core_no, thread_no; - for (pkg_no = 0; pkg_no < topology.num_packages; ++pkg_no) { - for (core_no = 0; core_no < topology.num_cores; ++core_no) { - for (thread_no = 0; thread_no < topology.num_threads; ++thread_no) { + for (unsigned int pkg_no = 0; pkg_no < topology.num_packages; ++pkg_no) { + for (unsigned int core_no = 0; core_no < topology.num_cores; ++core_no) { + for (unsigned int thread_no = 0; thread_no < topology.num_threads; ++thread_no) { struct thread_data *t; struct core_data *c; struct pkg_data *p; @@ -692,11 +691,10 @@ for_all_cpus_delta(const struct thread_data *thread_new_base, const struct core_ const struct thread_data *thread_old_base, const struct core_data *core_old_base, const struct pkg_data *pkg_old_base) { int retval; - unsigned int pkg_no, core_no, thread_no; - for (pkg_no = 0; pkg_no < topology.num_packages; ++pkg_no) { - for (core_no = 0; core_no < topology.num_cores; ++core_no) { - for (thread_no = 0; thread_no < topology.num_threads; ++thread_no) { + for (unsigned int pkg_no = 0; pkg_no < topology.num_packages; ++pkg_no) { + for (unsigned int core_no = 0; core_no < topology.num_cores; ++core_no) { + for (unsigned int thread_no = 0; thread_no < topology.num_threads; ++thread_no) { struct thread_data *t_delta; const struct thread_data *t_old, *t_new; struct core_data *c_delta; @@ -1150,7 +1148,6 @@ allocate_cpu_set(cpu_set_t ** set, size_t * size) { static int __attribute__((warn_unused_result)) topology_probe(void) { - unsigned int i; int ret; unsigned int max_package_id, max_core_id, max_threads; max_package_id = max_core_id = max_threads = 0; @@ -1187,7 +1184,7 @@ topology_probe(void) * For online cpus * find max_core_id, max_package_id */ - for (i = 0; i <= topology.max_cpu_id; ++i) { + for (unsigned int i = 0; i <= topology.max_cpu_id; ++i) { unsigned int num_threads; struct cpu_topology *cpu = &topology.cpus[i]; @@ -1252,7 +1249,6 @@ err: static int allocate_counters(struct thread_data **threads, struct core_data **cores, struct pkg_data **packages) { - unsigned int i; unsigned int total_threads, total_cores; if ((topology.num_threads == 0) @@ -1272,7 +1268,7 @@ allocate_counters(struct thread_data **threads, struct core_data **cores, struct return -1; } - for (i = 0; i < total_threads; ++i) + for (unsigned int i = 0; i < total_threads; ++i) (*threads)[i].cpu_id = topology.max_cpu_id + 1; total_cores = topology.num_cores * topology.num_packages; @@ -1322,9 +1318,7 @@ init_counter(struct thread_data *thread_base, struct core_data *core_base, static void initialize_counters(void) { - unsigned int cpu_id; - - for (cpu_id = 0; cpu_id <= topology.max_cpu_id; ++cpu_id) { + for (unsigned int cpu_id = 0; cpu_id <= topology.max_cpu_id; ++cpu_id) { if (cpu_is_not_present(cpu_id)) continue; init_counter(EVEN_COUNTERS, cpu_id); diff --git a/src/utils_cmd_flush.c b/src/utils_cmd_flush.c index 4c55cc76..1876150f 100644 --- a/src/utils_cmd_flush.c +++ b/src/utils_cmd_flush.c @@ -44,8 +44,6 @@ int handle_flush (FILE *fh, char *buffer) char **identifiers = NULL; size_t identifiers_num = 0; - size_t i; - #define PRINT_TO_SOCK(fh, ...) \ do { \ if (fprintf (fh, __VA_ARGS__) < 0) { \ @@ -123,15 +121,14 @@ int handle_flush (FILE *fh, char *buffer) } } /* while (*buffer != 0) */ - for (i = 0; (i == 0) || (i < plugins_num); i++) + for (size_t i = 0; (i == 0) || (i < plugins_num); i++) { char *plugin = NULL; - size_t j; if (plugins_num != 0) plugin = plugins[i]; - for (j = 0; (j == 0) || (j < identifiers_num); j++) + for (size_t j = 0; (j == 0) || (j < identifiers_num); j++) { char *identifier = NULL; int status; diff --git a/src/utils_cmd_getval.c b/src/utils_cmd_getval.c index 1185a03a..cd88760a 100644 --- a/src/utils_cmd_getval.c +++ b/src/utils_cmd_getval.c @@ -61,7 +61,6 @@ int handle_getval (FILE *fh, char *buffer) const data_set_t *ds; int status; - size_t i; if ((fh == NULL) || (buffer == NULL)) return (-1); @@ -146,7 +145,7 @@ int handle_getval (FILE *fh, char *buffer) print_to_socket (fh, "%zu Value%s found\n", values_num, (values_num == 1) ? "" : "s"); - for (i = 0; i < values_num; i++) + for (size_t i = 0; i < values_num; i++) { print_to_socket (fh, "%s=", ds->ds[i].name); if (isnan (values[i])) diff --git a/src/utils_cmd_listval.c b/src/utils_cmd_listval.c index c5f71a39..afbd01d0 100644 --- a/src/utils_cmd_listval.c +++ b/src/utils_cmd_listval.c @@ -34,8 +34,7 @@ #include "utils_parse_option.h" #define free_everything_and_return(status) do { \ - size_t j; \ - for (j = 0; j < number; j++) { \ + for (size_t j = 0; j < number; j++) { \ sfree(names[j]); \ names[j] = NULL; \ } \ @@ -61,7 +60,6 @@ int handle_listval (FILE *fh, char *buffer) char **names = NULL; cdtime_t *times = NULL; size_t number = 0; - size_t i; int status; DEBUG ("utils_cmd_listval: handle_listval (fh = %p, buffer = %s);", @@ -98,7 +96,7 @@ int handle_listval (FILE *fh, char *buffer) print_to_socket (fh, "%i Value%s found\n", (int) number, (number == 1) ? "" : "s"); - for (i = 0; i < number; i++) + for (size_t i = 0; i < number; i++) print_to_socket (fh, "%.3f %s\n", CDTIME_T_TO_DOUBLE (times[i]), names[i]); diff --git a/src/utils_crc32.c b/src/utils_crc32.c index f9eaf880..79d77a23 100644 --- a/src/utils_crc32.c +++ b/src/utils_crc32.c @@ -101,11 +101,10 @@ static unsigned int crc32_tab[] = { uint32_t crc32_buffer(const unsigned char *s, size_t len) { - size_t i; uint32_t ret; ret = 0; - for (i = 0; i < len; i++) + for (size_t i = 0; i < len; i++) ret = crc32_tab[(ret ^ s[i]) & 0xff] ^ (ret >> 8); return ret; } diff --git a/src/utils_curl_stats.c b/src/utils_curl_stats.c index 2865e9fe..0509ff43 100644 --- a/src/utils_curl_stats.c +++ b/src/utils_curl_stats.c @@ -160,7 +160,6 @@ static bool field_enabled (curl_stats_t *s, size_t offset) curl_stats_t *curl_stats_from_config (oconfig_item_t *ci) { curl_stats_t *s; - int i; if (ci == NULL) return NULL; @@ -169,7 +168,7 @@ curl_stats_t *curl_stats_from_config (oconfig_item_t *ci) if (s == NULL) return NULL; - for (i = 0; i < ci->children_num; ++i) + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *c = ci->children + i; size_t field; @@ -211,7 +210,6 @@ int curl_stats_dispatch (curl_stats_t *s, CURL *curl, const char *hostname, const char *plugin, const char *plugin_instance) { value_list_t vl = VALUE_LIST_INIT; - size_t field; if (s == NULL) return 0; @@ -229,7 +227,7 @@ int curl_stats_dispatch (curl_stats_t *s, CURL *curl, if (plugin_instance != NULL) sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); - for (field = 0; field < STATIC_ARRAY_SIZE (field_specs); ++field) + for (size_t field = 0; field < STATIC_ARRAY_SIZE (field_specs); ++field) { int status; diff --git a/src/utils_db_query.c b/src/utils_db_query.c index e576f947..26ebbf3f 100644 --- a/src/utils_db_query.c +++ b/src/utils_db_query.c @@ -126,7 +126,6 @@ static int udb_config_add_string (char ***ret_array, /* {{{ */ { char **array; size_t array_len; - int i; if (ci->values_num < 1) { @@ -135,7 +134,7 @@ static int udb_config_add_string (char ***ret_array, /* {{{ */ return (-1); } - for (i = 0; i < ci->values_num; i++) + for (int i = 0; i < ci->values_num; i++) { if (ci->values[i].type != OCONFIG_TYPE_STRING) { @@ -155,7 +154,7 @@ static int udb_config_add_string (char ***ret_array, /* {{{ */ } *ret_array = array; - for (i = 0; i < ci->values_num; i++) + for (int i = 0; i < ci->values_num; i++) { array[array_len] = strdup (ci->values[i].value.string); if (array[array_len] == NULL) @@ -200,7 +199,6 @@ static int udb_result_submit (udb_result_t *r, /* {{{ */ udb_query_t const *q, udb_query_preparation_area_t *q_area) { value_list_t vl = VALUE_LIST_INIT; - size_t i; int status; assert (r != NULL); @@ -216,7 +214,7 @@ static int udb_result_submit (udb_result_t *r, /* {{{ */ } vl.values_len = r_area->ds->ds_num; - for (i = 0; i < r->values_num; i++) + for (size_t i = 0; i < r->values_num; i++) { char *value_str = r_area->values_buffer[i]; @@ -286,7 +284,7 @@ static int udb_result_submit (udb_result_t *r, /* {{{ */ return (-ENOMEM); } - for (i = 0; i < r->metadata_num; i++) + for (size_t i = 0; i < r->metadata_num; i++) { status = meta_data_add_string (vl.meta, r->metadata[i], r_area->metadata_buffer[i]); @@ -332,17 +330,15 @@ static int udb_result_handle_result (udb_result_t *r, /* {{{ */ udb_result_preparation_area_t *r_area, udb_query_t const *q, char **column_values) { - size_t i; - assert (r && q_area && r_area); - for (i = 0; i < r->instances_num; i++) + for (size_t i = 0; i < r->instances_num; i++) r_area->instances_buffer[i] = column_values[r_area->instances_pos[i]]; - for (i = 0; i < r->values_num; i++) + for (size_t i = 0; i < r->values_num; i++) r_area->values_buffer[i] = column_values[r_area->values_pos[i]]; - for (i = 0; i < r->metadata_num; i++) + for (size_t i = 0; i < r->metadata_num; i++) r_area->metadata_buffer[i] = column_values[r_area->metadata_pos[i]]; if (q->plugin_instance_from) @@ -355,8 +351,6 @@ static int udb_result_prepare_result (udb_result_t const *r, /* {{{ */ udb_result_preparation_area_t *prep_area, char **column_names, size_t column_num) { - size_t i; - if ((r == NULL) || (prep_area == NULL)) return (-EINVAL); @@ -453,7 +447,7 @@ static int udb_result_prepare_result (udb_result_t const *r, /* {{{ */ /* }}} */ /* Determine the position of the plugin instance column {{{ */ - for (i = 0; i < r->instances_num; i++) + for (size_t i = 0; i < r->instances_num; i++) { size_t j; @@ -477,7 +471,7 @@ static int udb_result_prepare_result (udb_result_t const *r, /* {{{ */ /* Determine the position of the value columns {{{ */ - for (i = 0; i < r->values_num; i++) + for (size_t i = 0; i < r->values_num; i++) { size_t j; @@ -500,7 +494,7 @@ static int udb_result_prepare_result (udb_result_t const *r, /* {{{ */ } /* }}} for (i = 0; i < r->values_num; i++) */ /* Determine the position of the metadata columns {{{ */ - for (i = 0; i < r->metadata_num; i++) + for (size_t i = 0; i < r->metadata_num; i++) { size_t j; @@ -528,23 +522,21 @@ static int udb_result_prepare_result (udb_result_t const *r, /* {{{ */ static void udb_result_free (udb_result_t *r) /* {{{ */ { - size_t i; - if (r == NULL) return; sfree (r->type); sfree (r->instance_prefix); - for (i = 0; i < r->instances_num; i++) + for (size_t i = 0; i < r->instances_num; i++) sfree (r->instances[i]); sfree (r->instances); - for (i = 0; i < r->values_num; i++) + for (size_t i = 0; i < r->values_num; i++) sfree (r->values[i]); sfree (r->values); - for (i = 0; i < r->metadata_num; i++) + for (size_t i = 0; i < r->metadata_num; i++) sfree (r->metadata[i]); sfree (r->metadata); @@ -558,7 +550,6 @@ static int udb_result_create (const char *query_name, /* {{{ */ { udb_result_t *r; int status; - int i; if (ci->values_num != 0) { @@ -582,7 +573,7 @@ static int udb_result_create (const char *query_name, /* {{{ */ /* Fill the `udb_result_t' structure.. */ status = 0; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -680,7 +671,6 @@ int udb_query_create (udb_query_t ***ret_query_list, /* {{{ */ udb_query_t *q; int status; - int i; if ((ret_query_list == NULL) || (ret_query_list_len == NULL)) return (-EINVAL); @@ -715,7 +705,7 @@ int udb_query_create (udb_query_t ***ret_query_list, /* {{{ */ } /* Fill the `udb_query_t' structure.. */ - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -802,12 +792,10 @@ int udb_query_create (udb_query_t ***ret_query_list, /* {{{ */ void udb_query_free (udb_query_t **query_list, size_t query_list_len) /* {{{ */ { - size_t i; - if (query_list == NULL) return; - for (i = 0; i < query_list_len; i++) + for (size_t i = 0; i < query_list_len; i++) udb_query_free_one (query_list[i]); sfree (query_list); @@ -817,7 +805,6 @@ int udb_query_pick_from_list_by_name (const char *name, /* {{{ */ udb_query_t **src_list, size_t src_list_len, udb_query_t ***dst_list, size_t *dst_list_len) { - size_t i; int num_added; if ((name == NULL) || (src_list == NULL) || (dst_list == NULL) @@ -829,7 +816,7 @@ int udb_query_pick_from_list_by_name (const char *name, /* {{{ */ } num_added = 0; - for (i = 0; i < src_list_len; i++) + for (size_t i = 0; i < src_list_len; i++) { udb_query_t **tmp_list; size_t tmp_list_len; @@ -990,9 +977,7 @@ int udb_query_handle_result (udb_query_t const *q, /* {{{ */ #if defined(COLLECT_DEBUG) && COLLECT_DEBUG /* {{{ */ do { - size_t i; - - for (i = 0; i < prep_area->column_num; i++) + for (size_t i = 0; i < prep_area->column_num; i++) { DEBUG ("db query utils: udb_query_handle_result (%s, %s): " "column[%zu] = %s;", @@ -1053,9 +1038,7 @@ int udb_query_prepare_result (udb_query_t const *q, /* {{{ */ #if defined(COLLECT_DEBUG) && COLLECT_DEBUG do { - size_t i; - - for (i = 0; i < column_num; i++) + for (size_t i = 0; i < column_num; i++) { DEBUG ("db query utils: udb_query_prepare_result: " "query = %s; column[%zu] = %s;", diff --git a/src/utils_dns.c b/src/utils_dns.c index 12ba3655..2a1e2e51 100644 --- a/src/utils_dns.c +++ b/src/utils_dns.c @@ -195,9 +195,7 @@ static int cmp_in6_addr (const struct in6_addr *a, static inline int ignore_list_match (const struct in6_addr *addr) { - ip_list_t *ptr; - - for (ptr = IgnoreList; ptr != NULL; ptr = ptr->next) + for (ip_list_t *ptr = IgnoreList; ptr != NULL; ptr = ptr->next) if (cmp_in6_addr (addr, &ptr->addr) == 0) return (1); return (0); @@ -226,7 +224,6 @@ static void ignore_list_add (const struct in6_addr *addr) void ignore_list_add_name (const char *name) { struct addrinfo *ai_list; - struct addrinfo *ai_ptr; struct in6_addr addr; int status; @@ -234,7 +231,7 @@ void ignore_list_add_name (const char *name) if (status != 0) return; - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { if (ai_ptr->ai_family == AF_INET) { diff --git a/src/utils_format_graphite.c b/src/utils_format_graphite.c index a2deb3c7..e5234204 100644 --- a/src/utils_format_graphite.c +++ b/src/utils_format_graphite.c @@ -85,14 +85,12 @@ static int gr_format_values (char *ret, size_t ret_len, static void gr_copy_escape_part (char *dst, const char *src, size_t dst_len, char escape_char) { - size_t i; - memset (dst, 0, dst_len); if (src == NULL) return; - for (i = 0; i < dst_len; i++) + for (size_t i = 0; i < dst_len; i++) { if (src[i] == 0) { @@ -173,11 +171,9 @@ static int gr_format_name (char *ret, int ret_len, static void escape_graphite_string (char *buffer, char escape_char) { - char *head; - assert (strchr(GRAPHITE_FORBIDDEN, escape_char) == NULL); - for (head = buffer + strcspn(buffer, GRAPHITE_FORBIDDEN); + for (char *head = buffer + strcspn(buffer, GRAPHITE_FORBIDDEN); *head != '\0'; head += strcspn(head, GRAPHITE_FORBIDDEN)) *head = escape_char; @@ -189,14 +185,13 @@ int format_graphite (char *buffer, size_t buffer_size, unsigned int flags) { int status = 0; - size_t i; int buffer_pos = 0; gauge_t *rates = NULL; if (flags & GRAPHITE_STORE_RATES) rates = uc_get_rate (ds, vl); - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { char const *ds_name = NULL; char key[10*DATA_MAX_NAME_LEN]; diff --git a/src/utils_format_json.c b/src/utils_format_json.c index 99996b4c..5ca7fc83 100644 --- a/src/utils_format_json.c +++ b/src/utils_format_json.c @@ -35,7 +35,6 @@ static int json_escape_string (char *buffer, size_t buffer_size, /* {{{ */ const char *string) { - size_t src_pos; size_t dst_pos; if ((buffer == NULL) || (string == NULL)) @@ -57,7 +56,7 @@ static int json_escape_string (char *buffer, size_t buffer_size, /* {{{ */ /* Escape special characters */ BUFFER_ADD ('"'); - for (src_pos = 0; string[src_pos] != 0; src_pos++) + for (size_t src_pos = 0; string[src_pos] != 0; src_pos++) { if ((string[src_pos] == '"') || (string[src_pos] == '\\')) @@ -82,7 +81,6 @@ static int values_to_json (char *buffer, size_t buffer_size, /* {{{ */ const data_set_t *ds, const value_list_t *vl, int store_rates) { size_t offset = 0; - size_t i; gauge_t *rates = NULL; memset (buffer, 0, buffer_size); @@ -106,7 +104,7 @@ static int values_to_json (char *buffer, size_t buffer_size, /* {{{ */ } while (0) BUFFER_ADD ("["); - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { if (i > 0) BUFFER_ADD (","); @@ -161,7 +159,6 @@ static int dstypes_to_json (char *buffer, size_t buffer_size, /* {{{ */ const data_set_t *ds) { size_t offset = 0; - size_t i; memset (buffer, 0, buffer_size); @@ -178,7 +175,7 @@ static int dstypes_to_json (char *buffer, size_t buffer_size, /* {{{ */ } while (0) BUFFER_ADD ("["); - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { if (i > 0) BUFFER_ADD (","); @@ -198,7 +195,6 @@ static int dsnames_to_json (char *buffer, size_t buffer_size, /* {{{ */ const data_set_t *ds) { size_t offset = 0; - size_t i; memset (buffer, 0, buffer_size); @@ -215,7 +211,7 @@ static int dsnames_to_json (char *buffer, size_t buffer_size, /* {{{ */ } while (0) BUFFER_ADD ("["); - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { if (i > 0) BUFFER_ADD (","); @@ -236,7 +232,6 @@ static int meta_data_keys_to_json (char *buffer, size_t buffer_size, /* {{{ */ { size_t offset = 0; int status; - size_t i; buffer[0] = 0; @@ -251,7 +246,7 @@ static int meta_data_keys_to_json (char *buffer, size_t buffer_size, /* {{{ */ offset += ((size_t) status); \ } while (0) - for (i = 0; i < keys_num; ++i) + for (size_t i = 0; i < keys_num; ++i) { int type; char *key = keys[i]; @@ -315,7 +310,6 @@ static int meta_data_to_json (char *buffer, size_t buffer_size, /* {{{ */ char **keys = NULL; size_t keys_num; int status; - size_t i; if ((buffer == NULL) || (buffer_size == 0) || (meta == NULL)) return (EINVAL); @@ -327,7 +321,7 @@ static int meta_data_to_json (char *buffer, size_t buffer_size, /* {{{ */ status = meta_data_keys_to_json (buffer, buffer_size, meta, keys, keys_num); - for (i = 0; i < keys_num; ++i) + for (size_t i = 0; i < keys_num; ++i) sfree (keys[i]); sfree (keys); diff --git a/src/utils_format_kairosdb.c b/src/utils_format_kairosdb.c index febe2cb3..41055c7b 100644 --- a/src/utils_format_kairosdb.c +++ b/src/utils_format_kairosdb.c @@ -59,7 +59,6 @@ static int kairosdb_escape_string (char *buffer, size_t buffer_size, /* {{{ */ const char *string) { - size_t src_pos; size_t dst_pos; if ((buffer == NULL) || (string == NULL)) @@ -82,7 +81,7 @@ static int kairosdb_escape_string (char *buffer, size_t buffer_size, /* {{{ */ /* Escape special characters */ /* authorize -_. and alpha num but also escapes " */ BUFFER_ADD ('"'); - for (src_pos = 0; string[src_pos] != 0; src_pos++) + for (size_t src_pos = 0; string[src_pos] != 0; src_pos++) { if (isalnum(string[src_pos]) || 0x2d == string[src_pos] || @@ -223,7 +222,6 @@ static int value_list_to_kairosdb (char *buffer, size_t buffer_size, /* {{{ */ char temp[512]; size_t offset = 0; int status; - size_t i; memset (buffer, 0, buffer_size); @@ -245,7 +243,7 @@ static int value_list_to_kairosdb (char *buffer, size_t buffer_size, /* {{{ */ BUFFER_ADD (",\"%s\": %s", (key), temp); \ } while (0) - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { /* All value lists have a leading comma. The first one will be replaced with * a square bracket in `format_kairosdb_finalize'. */ diff --git a/src/utils_latency.c b/src/utils_latency.c index 2fb3f833..bfb9292c 100644 --- a/src/utils_latency.c +++ b/src/utils_latency.c @@ -97,9 +97,8 @@ static void change_bin_width (latency_counter_t *lc, cdtime_t latency) /* {{{ */ if (lc->num > 0) // if the histogram has data then iterate else skip { double width_change_ratio = ((double) old_bin_width) / ((double) new_bin_width); - size_t i; - for (i = 0; i < HISTOGRAM_NUM_BINS; i++) + for (size_t i = 0; i < HISTOGRAM_NUM_BINS; i++) { size_t new_bin = (size_t) (((double) i) * width_change_ratio); if (i == new_bin) diff --git a/src/utils_latency_test.c b/src/utils_latency_test.c index a0da51ea..9c3b0add 100644 --- a/src/utils_latency_test.c +++ b/src/utils_latency_test.c @@ -50,12 +50,11 @@ DEF_TEST(simple) { 99, 0.3, 99, 103, 20.6}, /* { -1, 0.3, 99, 103, 20.6}, see issue #1139 */ }; - size_t i; latency_counter_t *l; CHECK_NOT_NULL (l = latency_counter_create ()); - for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) { + for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++) { printf ("# case %zu: DOUBLE_TO_CDTIME_T(%g) = %"PRIu64"\n", i, cases[i].val, DOUBLE_TO_CDTIME_T (cases[i].val)); latency_counter_add (l, DOUBLE_TO_CDTIME_T (cases[i].val)); @@ -72,12 +71,11 @@ DEF_TEST(simple) DEF_TEST(percentile) { - size_t i; latency_counter_t *l; CHECK_NOT_NULL (l = latency_counter_create ()); - for (i = 0; i < 100; i++) { + for (size_t i = 0; i < 100; i++) { latency_counter_add (l, TIME_T_TO_CDTIME_T (((time_t) i) + 1)); } diff --git a/src/utils_mount.c b/src/utils_mount.c index a2e96a65..b8dabb17 100644 --- a/src/utils_mount.c +++ b/src/utils_mount.c @@ -216,7 +216,6 @@ uuidcache_init(void) FILE *procpt; char uuid[16], *label = NULL; char device[110]; - int firstPass; int handleOnFirst; if(uuidCache) { @@ -228,7 +227,7 @@ uuidcache_init(void) return; } - for(firstPass = 1; firstPass >= 0; firstPass--) { + for(int firstPass = 1; firstPass >= 0; firstPass--) { fseek(procpt, 0, SEEK_SET); while(fgets(line, sizeof(line), procpt)) { if(sscanf(line, " %d %d %d %[^\n ]", @@ -318,14 +317,13 @@ static char * get_spec_by_uuid(const char *s) { char uuid[16]; - int i; if(strlen(s) != 36 || s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-') { goto bad_uuid; } - for(i=0; i<16; i++) { + for(int i=0; i<16; i++) { if(*s == '-') { s++; } @@ -382,7 +380,6 @@ static char *get_device_name(const char *optstr) static cu_mount_t *cu_mount_listmntent (void) { cu_mount_t *last = *list; - struct tabmntent *p; struct mntent *mnt; struct tabmntent *mntlist; @@ -394,7 +391,7 @@ static cu_mount_t *cu_mount_listmntent (void) #endif /* COLLECT_DEBUG */ } - for(p = mntlist; p; p = p->next) { + for(struct tabmntent *p = mntlist; p; p = p->next) { char *loop = NULL, *device = NULL; mnt = p->ment; @@ -451,7 +448,6 @@ static cu_mount_t *cu_mount_getfsstat (void) STRUCT_STATFS *buf; int num; - int i; cu_mount_t *first = NULL; cu_mount_t *last = NULL; @@ -484,7 +480,7 @@ static cu_mount_t *cu_mount_getfsstat (void) return (NULL); } - for (i = 0; i < num; i++) + for (int i = 0; i < num; i++) { if ((new = calloc (1, sizeof (*new))) == NULL) break; @@ -741,10 +737,9 @@ cu_mount_t *cu_mount_getlist(cu_mount_t **list) void cu_mount_freelist (cu_mount_t *list) { - cu_mount_t *this; cu_mount_t *next; - for (this = list; this != NULL; this = next) + for (cu_mount_t *this = list; this != NULL; this = next) { next = this->next; diff --git a/src/utils_rrdcreate.c b/src/utils_rrdcreate.c index edb6c957..884de8f9 100644 --- a/src/utils_rrdcreate.c +++ b/src/utils_rrdcreate.c @@ -83,9 +83,7 @@ static pthread_mutex_t async_creation_lock = PTHREAD_MUTEX_INITIALIZER; */ static void rra_free (int rra_num, char **rra_def) /* {{{ */ { - int i; - - for (i = 0; i < rra_num; i++) + for (int i = 0; i < rra_num; i++) { sfree (rra_def[i]); } @@ -100,8 +98,7 @@ static void srrd_create_args_destroy (srrd_create_args_t *args) sfree (args->filename); if (args->argv != NULL) { - int i; - for (i = 0; i < args->argc; i++) + for (int i = 0; i < args->argc; i++) sfree (args->argv[i]); sfree (args->argv); } @@ -173,7 +170,6 @@ static int rra_get (char ***ret, const value_list_t *vl, /* {{{ */ int cdp_num; int cdp_len; - int i, j; /* The stepsize we use here: If it is user-set, use it. If not, use the * interval of the value-list. */ @@ -221,7 +217,7 @@ static int rra_get (char ***ret, const value_list_t *vl, /* {{{ */ rra_num = 0; cdp_len = 0; - for (i = 0; i < rts_num; i++) + for (int i = 0; i < rts_num; i++) { int span = rts[i]; @@ -237,7 +233,7 @@ static int rra_get (char ***ret, const value_list_t *vl, /* {{{ */ cdp_num = (int) ceil (((double) span) / ((double) (cdp_len * ss))); - for (j = 0; j < rra_types_num; j++) + for (int j = 0; j < rra_types_num; j++) { char buffer[128]; int status; @@ -270,9 +266,7 @@ static int rra_get (char ***ret, const value_list_t *vl, /* {{{ */ static void ds_free (int ds_num, char **ds_def) /* {{{ */ { - int i; - - for (i = 0; i < ds_num; i++) + for (int i = 0; i < ds_num; i++) if (ds_def[i] != NULL) free (ds_def[i]); free (ds_def); diff --git a/src/varnish.c b/src/varnish.c index 863f4971..bc6d294a 100644 --- a/src/varnish.c +++ b/src/varnish.c @@ -970,7 +970,6 @@ static int varnish_config_instance (const oconfig_item_t *ci) /* {{{ */ user_config_t *conf; user_data_t ud; char callback_name[DATA_MAX_NAME_LEN]; - int i; conf = calloc (1, sizeof (*conf)); if (conf == NULL) @@ -1005,7 +1004,7 @@ static int varnish_config_instance (const oconfig_item_t *ci) /* {{{ */ return (EINVAL); } - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -1149,9 +1148,7 @@ static int varnish_config_instance (const oconfig_item_t *ci) /* {{{ */ static int varnish_config (oconfig_item_t *ci) /* {{{ */ { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/virt.c b/src/virt.c index 93bb69b7..7df51c13 100644 --- a/src/virt.c +++ b/src/virt.c @@ -155,7 +155,7 @@ static int refresh_lists (void); static void init_value_list (value_list_t *vl, virDomainPtr dom) { - int i, n; + int n; const char *name; char uuid[VIR_UUID_STRING_BUFLEN]; @@ -164,7 +164,7 @@ init_value_list (value_list_t *vl, virDomainPtr dom) vl->host[0] = '\0'; /* Construct the hostname field according to HostnameFormat. */ - for (i = 0; i < HF_MAX_FIELDS; ++i) { + for (int i = 0; i < HF_MAX_FIELDS; ++i) { if (hostname_format[i] == hf_none) continue; @@ -195,7 +195,7 @@ init_value_list (value_list_t *vl, virDomainPtr dom) vl->host[sizeof (vl->host) - 1] = '\0'; /* Construct the plugin instance field according to PluginInstanceFormat. */ - for (i = 0; i < PLGINST_MAX_FIELDS; ++i) { + for (int i = 0; i < PLGINST_MAX_FIELDS; ++i) { if (plugin_instance_format[i] == plginst_none) continue; @@ -395,7 +395,7 @@ lv_config (const char *key, const char *value) if (strcasecmp (key, "HostnameFormat") == 0) { char *value_copy; char *fields[HF_MAX_FIELDS]; - int i, n; + int n; value_copy = strdup (value); if (value_copy == NULL) { @@ -410,7 +410,7 @@ lv_config (const char *key, const char *value) return -1; } - for (i = 0; i < n; ++i) { + for (int i = 0; i < n; ++i) { if (strcasecmp (fields[i], "hostname") == 0) hostname_format[i] = hf_hostname; else if (strcasecmp (fields[i], "name") == 0) @@ -425,7 +425,7 @@ lv_config (const char *key, const char *value) } sfree (value_copy); - for (i = n; i < HF_MAX_FIELDS; ++i) + for (int i = n; i < HF_MAX_FIELDS; ++i) hostname_format[i] = hf_none; return 0; @@ -434,7 +434,7 @@ lv_config (const char *key, const char *value) if (strcasecmp (key, "PluginInstanceFormat") == 0) { char *value_copy; char *fields[PLGINST_MAX_FIELDS]; - int i, n; + int n; value_copy = strdup (value); if (value_copy == NULL) { @@ -449,7 +449,7 @@ lv_config (const char *key, const char *value) return -1; } - for (i = 0; i < n; ++i) { + for (int i = 0; i < n; ++i) { if (strcasecmp (fields[i], "none") == 0) { plugin_instance_format[i] = plginst_none; break; @@ -465,7 +465,7 @@ lv_config (const char *key, const char *value) } sfree (value_copy); - for (i = n; i < PLGINST_MAX_FIELDS; ++i) + for (int i = n; i < PLGINST_MAX_FIELDS; ++i) plugin_instance_format[i] = plginst_none; return 0; @@ -493,7 +493,6 @@ static int lv_read (void) { time_t t; - int i; if (conn == NULL) { /* `conn_string == NULL' is acceptable. */ @@ -523,25 +522,24 @@ lv_read (void) } #if 0 - for (i = 0; i < nr_domains; ++i) + for (int i = 0; i < nr_domains; ++i) fprintf (stderr, "domain %s\n", virDomainGetName (domains[i])); - for (i = 0; i < nr_block_devices; ++i) + for (int i = 0; i < nr_block_devices; ++i) fprintf (stderr, "block device %d %s:%s\n", i, virDomainGetName (block_devices[i].dom), block_devices[i].path); - for (i = 0; i < nr_interface_devices; ++i) + for (int i = 0; i < nr_interface_devices; ++i) fprintf (stderr, "interface device %d %s:%s\n", i, virDomainGetName (interface_devices[i].dom), interface_devices[i].path); #endif /* Get CPU usage, memory, VCPU usage for each domain. */ - for (i = 0; i < nr_domains; ++i) { + for (int i = 0; i < nr_domains; ++i) { virDomainInfo info; virVcpuInfoPtr vinfo = NULL; virDomainMemoryStatPtr minfo = NULL; int status; - int j; status = virDomainGetInfo (domains[i], &info); if (status != 0) @@ -576,7 +574,7 @@ lv_read (void) continue; } - for (j = 0; j < info.nrVirtCpu; ++j) + for (int j = 0; j < info.nrVirtCpu; ++j) vcpu_submit (vinfo[j].cpuTime, domains[i], vinfo[j].number, "virt_vcpu"); @@ -597,7 +595,7 @@ lv_read (void) continue; } - for (j = 0; j < status; j++) { + for (int j = 0; j < status; j++) { memory_stats_submit ((gauge_t) minfo[j].val * 1024, domains[i], minfo[j].tag); } @@ -606,7 +604,7 @@ lv_read (void) /* Get block device stats for each domain. */ - for (i = 0; i < nr_block_devices; ++i) { + for (int i = 0; i < nr_block_devices; ++i) { struct _virDomainBlockStats stats; if (virDomainBlockStats (block_devices[i].dom, block_devices[i].path, @@ -625,7 +623,7 @@ lv_read (void) } /* for (nr_block_devices) */ /* Get interface stats for each domain. */ - for (i = 0; i < nr_interface_devices; ++i) { + for (int i = 0; i < nr_interface_devices; ++i) { struct _virDomainInterfaceStats stats; char *display_name = NULL; @@ -683,7 +681,6 @@ refresh_lists (void) } if (n > 0) { - int i; int *domids; /* Get list of domains. */ @@ -705,14 +702,13 @@ refresh_lists (void) free_domains (); /* Fetch each domain and add it to the list, unless ignore. */ - for (i = 0; i < n; ++i) { + for (int i = 0; i < n; ++i) { virDomainPtr dom = NULL; const char *name; char *xml = NULL; xmlDocPtr xml_doc = NULL; xmlXPathContextPtr xpath_ctx = NULL; xmlXPathObjectPtr xpath_obj = NULL; - int j; dom = virDomainLookupByID (conn, domids[i]); if (dom == NULL) { @@ -759,7 +755,7 @@ refresh_lists (void) xpath_obj->nodesetval == NULL) goto cont; - for (j = 0; j < xpath_obj->nodesetval->nodeNr; ++j) { + for (int j = 0; j < xpath_obj->nodesetval->nodeNr; ++j) { xmlNodePtr node; char *path = NULL; @@ -788,16 +784,15 @@ refresh_lists (void) xmlNodeSetPtr xml_interfaces = xpath_obj->nodesetval; - for (j = 0; j < xml_interfaces->nodeNr; ++j) { + for (int j = 0; j < xml_interfaces->nodeNr; ++j) { char *path = NULL; char *address = NULL; xmlNodePtr xml_interface; xml_interface = xml_interfaces->nodeTab[j]; if (!xml_interface) continue; - xmlNodePtr child = NULL; - for (child = xml_interface->children; child; child = child->next) { + for (xmlNodePtr child = xml_interface->children; child; child = child->next) { if (child->type != XML_ELEMENT_NODE) continue; if (xmlStrEqual(child->name, (const xmlChar *) "target")) { @@ -836,10 +831,8 @@ refresh_lists (void) static void free_domains (void) { - int i; - if (domains) { - for (i = 0; i < nr_domains; ++i) + for (int i = 0; i < nr_domains; ++i) virDomainFree (domains[i]); sfree (domains); } @@ -869,10 +862,8 @@ add_domain (virDomainPtr dom) static void free_block_devices (void) { - int i; - if (block_devices) { - for (i = 0; i < nr_block_devices; ++i) + for (int i = 0; i < nr_block_devices; ++i) sfree (block_devices[i].path); sfree (block_devices); } @@ -909,10 +900,8 @@ add_block_device (virDomainPtr dom, const char *path) static void free_interface_devices (void) { - int i; - if (interface_devices) { - for (i = 0; i < nr_interface_devices; ++i) { + for (int i = 0; i < nr_interface_devices; ++i) { sfree (interface_devices[i].path); sfree (interface_devices[i].address); sfree (interface_devices[i].number); diff --git a/src/write_graphite.c b/src/write_graphite.c index 0b7a94ff..2dce2d71 100644 --- a/src/write_graphite.c +++ b/src/write_graphite.c @@ -195,7 +195,6 @@ static int wg_flush_nolock (cdtime_t timeout, struct wg_callback *cb) static int wg_callback_init (struct wg_callback *cb) { struct addrinfo *ai_list; - struct addrinfo *ai_ptr; cdtime_t now; int status; @@ -230,7 +229,7 @@ static int wg_callback_init (struct wg_callback *cb) } assert (ai_list != NULL); - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { cb->sock_fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol); @@ -476,7 +475,6 @@ static int wg_config_node (oconfig_item_t *ci) struct wg_callback *cb; user_data_t user_data = { 0 }; char callback_name[DATA_MAX_NAME_LEN]; - int i; int status = 0; cb = calloc (1, sizeof (*cb)); @@ -513,7 +511,7 @@ static int wg_config_node (oconfig_item_t *ci) pthread_mutex_init (&cb->send_lock, /* attr = */ NULL); C_COMPLAIN_INIT (&cb->init_complaint); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -589,9 +587,7 @@ static int wg_config_node (oconfig_item_t *ci) static int wg_config (oconfig_item_t *ci) { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/write_http.c b/src/write_http.c index ec538b61..a12a7f56 100644 --- a/src/write_http.c +++ b/src/write_http.c @@ -629,7 +629,6 @@ static int wh_config_node (oconfig_item_t *ci) /* {{{ */ user_data_t user_data = { 0 }; char callback_name[DATA_MAX_NAME_LEN]; int status = 0; - int i; cb = calloc (1, sizeof (*cb)); if (cb == NULL) @@ -655,7 +654,7 @@ static int wh_config_node (oconfig_item_t *ci) /* {{{ */ if (strcasecmp ("URL", ci->key) == 0) cf_util_get_string (ci, &cb->location); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -789,9 +788,7 @@ static int wh_config_node (oconfig_item_t *ci) /* {{{ */ static int wh_config (oconfig_item_t *ci) /* {{{ */ { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/write_kafka.c b/src/write_kafka.c index 2df52a20..6364c6c3 100644 --- a/src/write_kafka.c +++ b/src/write_kafka.c @@ -241,7 +241,6 @@ static void kafka_topic_context_free(void *p) /* {{{ */ static void kafka_config_topic(rd_kafka_conf_t *conf, oconfig_item_t *ci) /* {{{ */ { int status; - int i; struct kafka_topic_context *tctx; char *key = NULL; char *val; @@ -293,7 +292,7 @@ static void kafka_config_topic(rd_kafka_conf_t *conf, oconfig_item_t *ci) /* {{{ goto errout; } - for (i = 0; i < ci->children_num; i++) { + for (int i = 0; i < ci->children_num; i++) { /* * The code here could be simplified but makes room * for easy adding of new options later on. @@ -412,7 +411,6 @@ static void kafka_config_topic(rd_kafka_conf_t *conf, oconfig_item_t *ci) /* {{{ static int kafka_config(oconfig_item_t *ci) /* {{{ */ { - int i; oconfig_item_t *child; rd_kafka_conf_t *conf; rd_kafka_conf_res_t ret; @@ -422,7 +420,7 @@ static int kafka_config(oconfig_item_t *ci) /* {{{ */ WARNING("cannot allocate kafka configuration."); return -1; } - for (i = 0; i < ci->children_num; i++) { + for (int i = 0; i < ci->children_num; i++) { child = &ci->children[i]; if (strcasecmp("Topic", child->key) == 0) { diff --git a/src/write_mongodb.c b/src/write_mongodb.c index 8d9ed9df..8fb13c34 100644 --- a/src/write_mongodb.c +++ b/src/write_mongodb.c @@ -76,7 +76,6 @@ static bson *wm_create_bson (const data_set_t *ds, /* {{{ */ { bson *ret; gauge_t *rates; - int i; ret = bson_alloc (); /* matched by bson_dealloc() */ if (ret == NULL) @@ -108,7 +107,7 @@ static bson *wm_create_bson (const data_set_t *ds, /* {{{ */ bson_append_string (ret, "type_instance", vl->type_instance); bson_append_start_array (ret, "values"); /* {{{ */ - for (i = 0; i < ds->ds_num; i++) + for (int i = 0; i < ds->ds_num; i++) { char key[16]; @@ -130,7 +129,7 @@ static bson *wm_create_bson (const data_set_t *ds, /* {{{ */ bson_append_finish_array (ret); /* }}} values */ bson_append_start_array (ret, "dstypes"); /* {{{ */ - for (i = 0; i < ds->ds_num; i++) + for (int i = 0; i < ds->ds_num; i++) { char key[16]; @@ -144,7 +143,7 @@ static bson *wm_create_bson (const data_set_t *ds, /* {{{ */ bson_append_finish_array (ret); /* }}} dstypes */ bson_append_start_array (ret, "dsnames"); /* {{{ */ - for (i = 0; i < ds->ds_num; i++) + for (int i = 0; i < ds->ds_num; i++) { char key[16]; @@ -271,7 +270,6 @@ static int wm_config_node (oconfig_item_t *ci) /* {{{ */ { wm_node_t *node; int status; - int i; node = calloc (1, sizeof (*node)); if (node == NULL) @@ -289,7 +287,7 @@ static int wm_config_node (oconfig_item_t *ci) /* {{{ */ return (status); } - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -358,9 +356,7 @@ static int wm_config_node (oconfig_item_t *ci) /* {{{ */ static int wm_config (oconfig_item_t *ci) /* {{{ */ { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/write_redis.c b/src/write_redis.c index 36089532..135a4587 100644 --- a/src/write_redis.c +++ b/src/write_redis.c @@ -168,7 +168,6 @@ static int wr_config_node (oconfig_item_t *ci) /* {{{ */ wr_node_t *node; int timeout; int status; - int i; node = calloc (1, sizeof (*node)); if (node == NULL) @@ -191,7 +190,7 @@ static int wr_config_node (oconfig_item_t *ci) /* {{{ */ return (status); } - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -251,9 +250,7 @@ static int wr_config_node (oconfig_item_t *ci) /* {{{ */ static int wr_config (oconfig_item_t *ci) /* {{{ */ { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/write_riemann.c b/src/write_riemann.c index 261327a3..10f89587 100644 --- a/src/write_riemann.c +++ b/src/write_riemann.c @@ -186,8 +186,6 @@ wrr_notification_to_message(struct riemann_host *host, /* {{{ */ riemann_event_t *event; char service_buffer[6 * DATA_MAX_NAME_LEN]; char const *severity; - notification_meta_t *meta; - size_t i; switch (n->severity) { case NOTIF_OKAY: @@ -228,18 +226,18 @@ wrr_notification_to_message(struct riemann_host *host, /* {{{ */ riemann_event_string_attribute_add(event, "type_instance", n->type_instance); - for (i = 0; i < riemann_attrs_num; i += 2) + for (size_t i = 0; i < riemann_attrs_num; i += 2) riemann_event_string_attribute_add(event, riemann_attrs[i], riemann_attrs[i + 1]); - for (i = 0; i < riemann_tags_num; i++) + for (size_t i = 0; i < riemann_tags_num; i++) riemann_event_tag_add(event, riemann_tags[i]); if (n->message[0] != 0) riemann_event_string_attribute_add(event, "description", n->message); /* Pull in values from threshold and add extra attributes */ - for (meta = n->meta; meta != NULL; meta = meta->next) { + for (notification_meta_t *meta = n->meta; meta != NULL; meta = meta->next) { if (strcasecmp("CurrentValue", meta->name) == 0 && meta->type == NM_TYPE_DOUBLE) { riemann_event_set(event, RIEMANN_EVENT_FIELD_METRIC_D, diff --git a/src/write_riemann_threshold.c b/src/write_riemann_threshold.c index 352c37f6..f2ba9dc8 100644 --- a/src/write_riemann_threshold.c +++ b/src/write_riemann_threshold.c @@ -131,7 +131,6 @@ static int ut_check_one_threshold (const data_set_t *ds, int *statuses) { /* {{{ */ int ret = -1; - size_t i; int status; gauge_t values_copy[ds->ds_num]; @@ -151,7 +150,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++; @@ -161,17 +160,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) { diff --git a/src/write_sensu.c b/src/write_sensu.c index ce9efb9f..63e9aabb 100644 --- a/src/write_sensu.c +++ b/src/write_sensu.c @@ -95,8 +95,7 @@ static int add_str_to_list(struct str_list *strs, static void free_str_list(struct str_list *strs) /* {{{ */ { - int i; - for (i=0; inb_strs; i++) + for (int i=0; inb_strs; i++) free(strs->strs[i]); free(strs->strs); } @@ -105,7 +104,6 @@ static void free_str_list(struct str_list *strs) /* {{{ */ static int sensu_connect(struct sensu_host *host) /* {{{ */ { int e; - struct addrinfo *ai; char const *node; char const *service; @@ -135,7 +133,7 @@ static int sensu_connect(struct sensu_host *host) /* {{{ */ struct linger so_linger; host->s = -1; - for (ai = host->res; ai != NULL; ai = ai->ai_next) { + for (struct addrinfo *ai = host->res; ai != NULL; ai = ai->ai_next) { // create the socket if ((host->s = socket(ai->ai_family, ai->ai_socktype, @@ -179,7 +177,6 @@ static char *build_json_str_list(const char *tag, struct str_list const *list) / int res; char *ret_str = NULL; char *temp_str; - int i; if (list->nb_strs == 0) { ret_str = malloc(sizeof(char)); if (ret_str == NULL) { @@ -195,7 +192,7 @@ static char *build_json_str_list(const char *tag, struct str_list const *list) / free(ret_str); return NULL; } - for (i=1; inb_strs; i++) { + for (int i=1; inb_strs; i++) { res = asprintf(&ret_str, "%s, \"%s\"", temp_str, list->strs[i]); free(temp_str); if (res == -1) { @@ -261,9 +258,8 @@ static int sensu_format_name2(char *ret, int ret_len, static void in_place_replace_sensu_name_reserved(char *orig_name) /* {{{ */ { - int i; int len=strlen(orig_name); - for (i=0; imeta; meta != NULL; meta = meta->next) { + for (notification_meta_t *meta = n->meta; meta != NULL; meta = meta->next) { if (strcasecmp("CurrentValue", meta->name) == 0 && meta->type == NM_TYPE_DOUBLE) { res = asprintf(&temp_str, "%s, \"current_value\": \"%.8f\"", ret_str, meta->nm_value.nm_double); free(ret_str); @@ -839,7 +833,6 @@ static int sensu_write(const data_set_t *ds, /* {{{ */ int statuses[vl->values_len]; struct sensu_host *host = ud->data; gauge_t *rates = NULL; - size_t i; char *msg; pthread_mutex_lock(&host->lock); @@ -853,7 +846,7 @@ static int sensu_write(const data_set_t *ds, /* {{{ */ return -1; } } - for (i = 0; i < vl->values_len; i++) { + for (size_t i = 0; i < vl->values_len; i++) { msg = sensu_value_to_json(host, ds, vl, (int) i, rates, statuses[i]); if (msg == NULL) { sfree(rates); @@ -933,7 +926,6 @@ static int sensu_config_node(oconfig_item_t *ci) /* {{{ */ { struct sensu_host *host = NULL; int status = 0; - int i; oconfig_item_t *child; char callback_name[DATA_MAX_NAME_LEN]; user_data_t ud; @@ -968,7 +960,7 @@ static int sensu_config_node(oconfig_item_t *ci) /* {{{ */ return -1; } - for (i = 0; i < ci->children_num; i++) { + for (int i = 0; i < ci->children_num; i++) { child = &ci->children[i]; status = 0; @@ -1109,7 +1101,6 @@ static int sensu_config_node(oconfig_item_t *ci) /* {{{ */ static int sensu_config(oconfig_item_t *ci) /* {{{ */ { - int i; oconfig_item_t *child; int status; struct str_list sensu_tags_arr; @@ -1117,7 +1108,7 @@ static int sensu_config(oconfig_item_t *ci) /* {{{ */ sensu_tags_arr.nb_strs = 0; sensu_tags_arr.strs = NULL; - for (i = 0; i < ci->children_num; i++) { + for (int i = 0; i < ci->children_num; i++) { child = &ci->children[i]; if (strcasecmp("Node", child->key) == 0) { diff --git a/src/write_tsdb.c b/src/write_tsdb.c index 78166b18..309418a1 100644 --- a/src/write_tsdb.c +++ b/src/write_tsdb.c @@ -157,7 +157,6 @@ static int wt_flush_nolock(cdtime_t timeout, struct wt_callback *cb) static int wt_callback_init(struct wt_callback *cb) { struct addrinfo *ai_list; - struct addrinfo *ai_ptr; int status; const char *node = cb->node ? cb->node : WT_DEFAULT_NODE; @@ -181,7 +180,7 @@ static int wt_callback_init(struct wt_callback *cb) } assert (ai_list != NULL); - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { cb->sock_fd = socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol); @@ -503,7 +502,6 @@ static int wt_write_messages(const data_set_t *ds, const value_list_t *vl, char values[512]; int status; - size_t i; if (0 != strcmp(ds->type, vl->type)) { @@ -512,7 +510,7 @@ static int wt_write_messages(const data_set_t *ds, const value_list_t *vl, return -1; } - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { const char *ds_name = NULL; @@ -573,7 +571,6 @@ static int wt_config_tsd(oconfig_item_t *ci) struct wt_callback *cb; user_data_t user_data = { 0 }; char callback_name[DATA_MAX_NAME_LEN]; - int i; cb = calloc(1, sizeof(*cb)); if (cb == NULL) @@ -589,7 +586,7 @@ static int wt_config_tsd(oconfig_item_t *ci) pthread_mutex_init (&cb->send_lock, NULL); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -626,9 +623,7 @@ static int wt_config_tsd(oconfig_item_t *ci) static int wt_config(oconfig_item_t *ci) { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/xencpu.c b/src/xencpu.c index 59fbcb98..f1cd9388 100644 --- a/src/xencpu.c +++ b/src/xencpu.c @@ -142,8 +142,8 @@ static int xencpu_read (void) return (-1); } - int cpu, status; - for (cpu = 0; cpu < nr_cpus; cpu++) { + int status; + for (int cpu = 0; cpu < nr_cpus; cpu++) { gauge_t rate = NAN; value_t value = {.derive = cpu_info[cpu].idletime}; diff --git a/src/zfs_arc.c b/src/zfs_arc.c index c5493d83..3f5c398f 100644 --- a/src/zfs_arc.c +++ b/src/zfs_arc.c @@ -90,12 +90,10 @@ static long long get_zfs_value(kstat_t *ksp, const char *key) static void free_zfs_values (kstat_t *ksp) { - llentry_t *e; - if (ksp == NULL) return; - for (e = llist_head (ksp); e != NULL; e = e->next) + for (llentry_t *e = llist_head (ksp); e != NULL; e = e->next) { sfree (e->key); sfree (e->value); diff --git a/src/zookeeper.c b/src/zookeeper.c index 04798582..84174853 100644 --- a/src/zookeeper.c +++ b/src/zookeeper.c @@ -106,7 +106,6 @@ static int zookeeper_connect (void) { int sk = -1; int status; - struct addrinfo *ai; struct addrinfo *ai_list; const char *host; const char *port; @@ -130,7 +129,7 @@ static int zookeeper_connect (void) return (-1); } - for (ai = ai_list; ai != NULL; ai = ai->ai_next) + for (struct addrinfo *ai = ai_list; ai != NULL; ai = ai->ai_next) { sk = socket (ai->ai_family, SOCK_STREAM, 0); if (sk < 0) -- 2.11.0