diff options
author | Antonio Borneo <borneo.antonio@gmail.com> | 2023-08-06 10:32:46 +0200 |
---|---|---|
committer | Evgeniy Naydanov <109669442+en-sc@users.noreply.github.com> | 2024-01-29 13:36:27 +0300 |
commit | be81c6ffe018572012f69c19782cca7477acf924 (patch) | |
tree | 6974ff1c019f8857d6bb4ee472594739e24245f2 /src/helper/command.c | |
parent | cdf89dcd2ee2b5b0b2b7322dd8d045ecf6fc19f3 (diff) | |
download | riscv-openocd-be81c6ffe018572012f69c19782cca7477acf924.zip riscv-openocd-be81c6ffe018572012f69c19782cca7477acf924.tar.gz riscv-openocd-be81c6ffe018572012f69c19782cca7477acf924.tar.bz2 |
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
Diffstat (limited to 'src/helper/command.c')
-rw-r--r-- | src/helper/command.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/helper/command.c b/src/helper/command.c index 9602333..f7ec0e2 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -161,15 +161,13 @@ static void script_command_args_free(char **words, unsigned nwords) free(words); } -static char **script_command_args_alloc( - unsigned argc, Jim_Obj * const *argv, unsigned *nwords) +static char **script_command_args_alloc(unsigned int argc, Jim_Obj * const *argv) { char **words = malloc(argc * sizeof(char *)); if (!words) return NULL; - unsigned i; - for (i = 0; i < argc; i++) { + for (unsigned int i = 0; i < argc; i++) { const char *w = Jim_GetString(argv[i], NULL); words[i] = strdup(w); if (!words[i]) { @@ -177,7 +175,6 @@ static char **script_command_args_alloc( return NULL; } } - *nwords = i; 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); /* use c->handler */ - unsigned int nwords; - char **words = script_command_args_alloc(argc, argv, &nwords); + unsigned int nwords = argc; + char **words = script_command_args_alloc(argc, argv); if (!words) return JIM_ERR; |