helper/command: simplify script_command_args_alloc()
The output parameter nwords is always equal to the input parameter argc, when the function succeeds. Drop the parameter nwords and let the caller use directly the value in argc. While there, convert some 'unsigned' to 'unsigned int'. Change-Id: Ie3d8ce1351792f3c07fe39cdcbcd180fd24dc928 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/8054 Tested-by: jenkins
This commit is contained in:
parent
cdf89dcd2e
commit
be81c6ffe0
|
@ -161,15 +161,13 @@ static void script_command_args_free(char **words, unsigned nwords)
|
||||||
free(words);
|
free(words);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char **script_command_args_alloc(
|
static char **script_command_args_alloc(unsigned int argc, Jim_Obj * const *argv)
|
||||||
unsigned argc, Jim_Obj * const *argv, unsigned *nwords)
|
|
||||||
{
|
{
|
||||||
char **words = malloc(argc * sizeof(char *));
|
char **words = malloc(argc * sizeof(char *));
|
||||||
if (!words)
|
if (!words)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
unsigned i;
|
for (unsigned int i = 0; i < argc; i++) {
|
||||||
for (i = 0; i < argc; i++) {
|
|
||||||
const char *w = Jim_GetString(argv[i], NULL);
|
const char *w = Jim_GetString(argv[i], NULL);
|
||||||
words[i] = strdup(w);
|
words[i] = strdup(w);
|
||||||
if (!words[i]) {
|
if (!words[i]) {
|
||||||
|
@ -177,7 +175,6 @@ static char **script_command_args_alloc(
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*nwords = i;
|
|
||||||
return words;
|
return words;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -901,8 +898,8 @@ static int exec_command(Jim_Interp *interp, struct command_context *cmd_ctx,
|
||||||
return c->jim_handler(interp, argc, argv);
|
return c->jim_handler(interp, argc, argv);
|
||||||
|
|
||||||
/* use c->handler */
|
/* use c->handler */
|
||||||
unsigned int nwords;
|
unsigned int nwords = argc;
|
||||||
char **words = script_command_args_alloc(argc, argv, &nwords);
|
char **words = script_command_args_alloc(argc, argv);
|
||||||
if (!words)
|
if (!words)
|
||||||
return JIM_ERR;
|
return JIM_ERR;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue