Declare loop variable in the loop expression.
authorSebastian Harl <sh@tokkee.org>
Sun, 25 Sep 2016 11:23:43 +0000 (13:23 +0200)
committerSebastian Harl <sh@tokkee.org>
Sun, 25 Sep 2016 11:23:43 +0000 (13:23 +0200)
src/utils_cmd_flush.c
src/utils_cmd_putval.c
src/utils_cmds.c
src/utils_cmds_test.c

index 320b063..9ef50ff 100644 (file)
@@ -136,8 +136,6 @@ cmd_status_t cmd_handle_flush (FILE *fh, char *buffer)
        int error   = 0;
        int status;
 
        int error   = 0;
        int status;
 
-       size_t i;
-
        if ((fh == NULL) || (buffer == NULL))
                return (-1);
 
        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);
        }
 
                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;
 
        {
                char *plugin = NULL;
 
index b253785..691f1f8 100644 (file)
@@ -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;
 
        const data_set_t *ds;
        value_list_t vl = VALUE_LIST_INIT;
-       size_t i;
 
        if ((ret_putval == NULL) || (opts == NULL))
        {
 
        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;
 
        /* 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;
 
        {
                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)
 {
 
 void cmd_destroy_putval (cmd_putval_t *putval)
 {
-       size_t i;
-
        if (putval == NULL)
                return;
 
        sfree (putval->raw_identifier);
 
        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);
        {
                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;
 {
        cmd_error_handler_t err = { cmd_error_fh, fh };
        cmd_t cmd;
-       size_t i;
 
        int status;
 
 
        int status;
 
@@ -275,7 +271,7 @@ cmd_status_t cmd_handle_putval (FILE *fh, char *buffer)
                return (CMD_UNKNOWN_COMMAND);
        }
 
                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)
                plugin_dispatch_values (&cmd.cmd.putval.vl[i]);
 
        if (fh != stdout)
index f667596..1f53ad1 100644 (file)
@@ -49,7 +49,7 @@ static cmd_status_t cmd_split (char *buffer,
                size_t *ret_len, char ***ret_fields,
                cmd_error_handler_t *err)
 {
                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;
        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;
 
        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. */
        {
                /* 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;
        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]))
                {
        {
                if (isspace ((int)string[0]))
                {
index f5743e9..9e9eae3 100644 (file)
@@ -278,9 +278,8 @@ DEF_TEST(parse)
 {
        cmd_error_handler_t err = { error_cb, NULL };
        int test_result = 0;
 {
        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];
                char *input = strdup (parse_data[i].input);
 
                char description[1024];