]> git.sur5r.net Git - openocd/commitdiff
command_handler_t: make argc unsigned
authorZachary T Welch <zw@superlucidity.net>
Tue, 10 Nov 2009 08:02:18 +0000 (00:02 -0800)
committerZachary T Welch <zw@superlucidity.net>
Fri, 13 Nov 2009 18:55:27 +0000 (10:55 -0800)
The number of command arguments will always be 0 or more, so use
the right type in handlers.  This has a cascading effect up through
the layers, but the new COMMAND_HANDLER macros prevented total chaos.

src/flash/cfi.c
src/flash/nand.c
src/helper/command.h
src/helper/ioutil.c
src/jtag/ft2232.c
src/svf/svf.c
src/target/arm9tdmi.c

index 08c43580e0403316403fd402ccc8d47efe13d6cf..88f57df27746ef2ae676836ac6f5e5e57da9a856 100644 (file)
@@ -604,9 +604,6 @@ static int cfi_register_commands(struct command_context_s *cmd_ctx)
 FLASH_BANK_COMMAND_HANDLER(cfi_flash_bank_command)
 {
        cfi_flash_bank_t *cfi_info;
-       int i;
-       (void) cmd_ctx;
-       (void) cmd;
 
        if (argc < 6)
        {
@@ -635,7 +632,7 @@ FLASH_BANK_COMMAND_HANDLER(cfi_flash_bank_command)
        cfi_info->jedec_probe = 0;
        cfi_info->not_cfi = 0;
 
-       for (i = 6; i < argc; i++)
+       for (unsigned i = 6; i < argc; i++)
        {
                if (strcmp(args[i], "x16_as_x8") == 0)
                {
index 88d3e42cec5ebb23198a3ff943574bcf4d87920f..26eb63ad20ae92bb86ba2f9f49e3059029db623e 100644 (file)
@@ -1315,8 +1315,7 @@ COMMAND_HANDLER(handle_nand_write_command)
 
        if (argc > 3)
        {
-               int i;
-               for (i = 3; i < argc; i++)
+               for (unsigned i = 3; i < argc; i++)
                {
                        if (!strcmp(args[i], "oob_raw"))
                                oob_format |= NAND_OOB_RAW;
@@ -1485,8 +1484,7 @@ COMMAND_HANDLER(handle_nand_dump_command)
 
        if (argc > 4)
        {
-               int i;
-               for (i = 4; i < argc; i++)
+               for (unsigned i = 4; i < argc; i++)
                {
                        if (!strcmp(args[i], "oob_raw"))
                                oob_format |= NAND_OOB_RAW;
index 74c6f367b0bc88452fbff38f4deae9e37e07eb78..557731563675ea8fae2e1729cdc58774ba61a929 100644 (file)
@@ -88,7 +88,7 @@ typedef struct command_context_s
  */
 #define __COMMAND_HANDLER(name, extra...) \
                int name(struct command_context_s *cmd_ctx, \
-                               char *cmd, char **args, int argc, ##extra)
+                               char *cmd, char **args, unsigned argc, ##extra)
 
 /**
  * Use this to macro to call a command helper (or a nested handler).
index 1423462c1088b45458fcc08070cff297caeb2da7..3a62961142d7d6556d7c8416b60d352d0a201540 100644 (file)
@@ -214,9 +214,9 @@ COMMAND_HANDLER(handle_append_command)
        config_file = fopen(args[0], "a");
        if (config_file != NULL)
        {
-               int i;
                fseek(config_file, 0, SEEK_END);
 
+               unsigned i;
                for (i = 1; i < argc; i++)
                {
                        if (fwrite(args[i], 1, strlen(args[i]), config_file) != strlen(args[i]))
index 6d2335698b661aa392291611e3a62ec921282191..39036bcb9e6a51aba169daba0bb2d3681a5c09fc 100644 (file)
@@ -2874,8 +2874,7 @@ COMMAND_HANDLER(ft2232_handle_vid_pid_command)
                argc -= 1;
        }
 
-       int i;
-       int retval = ERROR_OK;
+       unsigned i;
        for (i = 0; i < argc; i += 2)
        {
                COMMAND_PARSE_NUMBER(u16, args[i], ft2232_vid[i >> 1]);
@@ -2888,7 +2887,7 @@ COMMAND_HANDLER(ft2232_handle_vid_pid_command)
         */
        ft2232_vid[i >> 1] = ft2232_pid[i >> 1] = 0;
 
-       return retval;
+       return ERROR_OK;
 }
 
 COMMAND_HANDLER(ft2232_handle_latency_command)
index 76b067047e7fb2afbfc88ac5e45dee6372f16c8b..8f2ee80c6ec9d95cee57376e38d36d0292049766 100644 (file)
@@ -304,7 +304,7 @@ int svf_add_statemove(tap_state_t state_to)
 COMMAND_HANDLER(handle_svf_command)
 {
 #define SVF_NUM_OF_OPTIONS                     1
-       int command_num = 0, i;
+       int command_num = 0;
        int ret = ERROR_OK;
        long long time_ago;
 
@@ -316,7 +316,7 @@ COMMAND_HANDLER(handle_svf_command)
 
        // parse variant
        svf_quiet = 0;
-       for (i = 1; i < argc; i++)
+       for (unsigned i = 1; i < argc; i++)
        {
                if (!strcmp(args[i], "quiet"))
                {
index 112ec2a46455655b1ad68aedd93e627d9c40ab5f..416fe794743779634f12ae4945f24bf3cb9dffed 100644 (file)
@@ -862,7 +862,6 @@ COMMAND_HANDLER(handle_arm9tdmi_catch_vectors_command)
        struct arm7_9_common_s *arm7_9 = target_to_arm7_9(target);
        reg_t *vector_catch;
        uint32_t vector_catch_value;
-       int i, j;
 
        /* it's uncommon, but some ARM7 chips can support this */
        if (arm7_9->common_magic != ARM7_9_COMMON_MAGIC
@@ -894,9 +893,10 @@ COMMAND_HANDLER(handle_arm9tdmi_catch_vectors_command)
                }
                else
                {
-                       for (i = 0; i < argc; i++)
+                       for (unsigned i = 0; i < argc; i++)
                        {
                                /* go through list of vectors */
+                               unsigned j;
                                for (j = 0; arm9tdmi_vectors[j].name; j++)
                                {
                                        if (strcmp(args[i], arm9tdmi_vectors[j].name) == 0)
@@ -927,7 +927,7 @@ COMMAND_HANDLER(handle_arm9tdmi_catch_vectors_command)
        }
 
        /* output current settings */
-       for (i = 0; arm9tdmi_vectors[i].name; i++) {
+       for (unsigned i = 0; arm9tdmi_vectors[i].name; i++) {
                command_print(cmd_ctx, "%s: %s", arm9tdmi_vectors[i].name,
                        (vector_catch_value & arm9tdmi_vectors[i].value)
                                ? "catch" : "don't catch");