From: Sebastian Harl Date: Sun, 25 Sep 2016 11:23:43 +0000 (+0200) Subject: Declare loop variable in the loop expression. X-Git-Tag: collectd-5.7.0~49^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b7c67e8ccfc70f52f8533df9502424de85074eee;p=collectd.git Declare loop variable in the loop expression. --- diff --git a/src/utils_cmd_flush.c b/src/utils_cmd_flush.c index 320b0632..9ef50ffb 100644 --- a/src/utils_cmd_flush.c +++ b/src/utils_cmd_flush.c @@ -136,8 +136,6 @@ cmd_status_t cmd_handle_flush (FILE *fh, char *buffer) int error = 0; int status; - size_t i; - if ((fh == NULL) || (buffer == NULL)) return (-1); @@ -154,7 +152,7 @@ cmd_status_t cmd_handle_flush (FILE *fh, char *buffer) return (CMD_UNKNOWN_COMMAND); } - for (i = 0; (i == 0) || (i < cmd.cmd.flush.plugins_num); i++) + for (size_t i = 0; (i == 0) || (i < cmd.cmd.flush.plugins_num); i++) { char *plugin = NULL; diff --git a/src/utils_cmd_putval.c b/src/utils_cmd_putval.c index b2537859..691f1f80 100644 --- a/src/utils_cmd_putval.c +++ b/src/utils_cmd_putval.c @@ -86,7 +86,6 @@ cmd_status_t cmd_parse_putval (size_t argc, char **argv, const data_set_t *ds; value_list_t vl = VALUE_LIST_INIT; - size_t i; if ((ret_putval == NULL) || (opts == NULL)) { @@ -174,7 +173,7 @@ cmd_status_t cmd_parse_putval (size_t argc, char **argv, /* All the remaining fields are part of the option list. */ result = CMD_OK; - for (i = 1; i < argc; ++i) + for (size_t i = 1; i < argc; ++i) { value_list_t *tmp; @@ -235,14 +234,12 @@ cmd_status_t cmd_parse_putval (size_t argc, char **argv, void cmd_destroy_putval (cmd_putval_t *putval) { - size_t i; - if (putval == NULL) return; sfree (putval->raw_identifier); - for (i = 0; i < putval->vl_num; ++i) + for (size_t i = 0; i < putval->vl_num; ++i) { if (i == 0) /* values is shared between all entries */ sfree (putval->vl[i].values); @@ -258,7 +255,6 @@ cmd_status_t cmd_handle_putval (FILE *fh, char *buffer) { cmd_error_handler_t err = { cmd_error_fh, fh }; cmd_t cmd; - size_t i; int status; @@ -275,7 +271,7 @@ cmd_status_t cmd_handle_putval (FILE *fh, char *buffer) return (CMD_UNKNOWN_COMMAND); } - for (i = 0; i < cmd.cmd.putval.vl_num; ++i) + for (size_t i = 0; i < cmd.cmd.putval.vl_num; ++i) plugin_dispatch_values (&cmd.cmd.putval.vl[i]); if (fh != stdout) diff --git a/src/utils_cmds.c b/src/utils_cmds.c index f6675969..1f53ad1d 100644 --- a/src/utils_cmds.c +++ b/src/utils_cmds.c @@ -49,7 +49,7 @@ static cmd_status_t cmd_split (char *buffer, size_t *ret_len, char ***ret_fields, cmd_error_handler_t *err) { - char *string, *field; + char *field; bool in_field, in_quotes; size_t estimate, len; @@ -57,7 +57,7 @@ static cmd_status_t cmd_split (char *buffer, estimate = 0; in_field = false; - for (string = buffer; *string != '\0'; ++string) + for (char *string = buffer; *string != '\0'; ++string) { /* Make a quick worst-case estimate of the number of fields by * counting spaces and ignoring quotation marks. */ @@ -102,7 +102,7 @@ static cmd_status_t cmd_split (char *buffer, field = NULL; in_field = false; in_quotes = false; - for (string = buffer; *string != '\0'; string++) + for (char *string = buffer; *string != '\0'; string++) { if (isspace ((int)string[0])) { diff --git a/src/utils_cmds_test.c b/src/utils_cmds_test.c index f5743e99..9e9eae3b 100644 --- a/src/utils_cmds_test.c +++ b/src/utils_cmds_test.c @@ -278,9 +278,8 @@ DEF_TEST(parse) { cmd_error_handler_t err = { error_cb, NULL }; int test_result = 0; - size_t i; - for (i = 0; i < STATIC_ARRAY_SIZE (parse_data); i++) { + for (size_t i = 0; i < STATIC_ARRAY_SIZE (parse_data); i++) { char *input = strdup (parse_data[i].input); char description[1024];