From: Zachary T Welch Date: Tue, 10 Nov 2009 08:02:18 +0000 (-0800) Subject: command_handler_t: make argc unsigned X-Git-Tag: v0.4.0-rc1~800 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d22270e0ed291d3b08fd03a25181b279ca5e0911;p=openocd command_handler_t: make argc unsigned 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. --- diff --git a/src/flash/cfi.c b/src/flash/cfi.c index 08c43580..88f57df2 100644 --- a/src/flash/cfi.c +++ b/src/flash/cfi.c @@ -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) { diff --git a/src/flash/nand.c b/src/flash/nand.c index 88d3e42c..26eb63ad 100644 --- a/src/flash/nand.c +++ b/src/flash/nand.c @@ -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; diff --git a/src/helper/command.h b/src/helper/command.h index 74c6f367..55773156 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -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). diff --git a/src/helper/ioutil.c b/src/helper/ioutil.c index 1423462c..3a629611 100644 --- a/src/helper/ioutil.c +++ b/src/helper/ioutil.c @@ -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])) diff --git a/src/jtag/ft2232.c b/src/jtag/ft2232.c index 6d233569..39036bcb 100644 --- a/src/jtag/ft2232.c +++ b/src/jtag/ft2232.c @@ -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) diff --git a/src/svf/svf.c b/src/svf/svf.c index 76b06704..8f2ee80c 100644 --- a/src/svf/svf.c +++ b/src/svf/svf.c @@ -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")) { diff --git a/src/target/arm9tdmi.c b/src/target/arm9tdmi.c index 112ec2a4..416fe794 100644 --- a/src/target/arm9tdmi.c +++ b/src/target/arm9tdmi.c @@ -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");