Commit d22270e0 authored by Zachary T Welch's avatar Zachary T Welch
Browse files

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.
parent a585bdf7
......@@ -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)
{
......
......@@ -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;
......
......@@ -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).
......
......@@ -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]))
......
......@@ -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)
......
......@@ -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"))
{
......
......@@ -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");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment