helper/command: fix clang static analyzer warning
Warning: line 955, column 3 Argument to free() is the address of a global variable, which is not memory allocated by malloc() It is definitely a false alarm. Simplify concatenation of arguments and allocate a string always to silence the warning. Change-Id: I5ac4cc610fc35224df0b16ef4f7102700363249f Signed-off-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-on: http://openocd.zylin.com/5904 Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com> Tested-by: jenkins Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
This commit is contained in:
parent
cd19f46688
commit
a932810f9d
|
@ -920,38 +920,28 @@ COMMAND_HANDLER(handle_help_command)
|
|||
bool full = strcmp(CMD_NAME, "help") == 0;
|
||||
int retval;
|
||||
struct command *c = CMD_CTX->commands;
|
||||
char *cmd_match = NULL;
|
||||
char *cmd_match;
|
||||
|
||||
if (CMD_ARGC == 0)
|
||||
cmd_match = "";
|
||||
else if (CMD_ARGC >= 1) {
|
||||
unsigned i;
|
||||
if (CMD_ARGC <= 0)
|
||||
cmd_match = strdup("");
|
||||
|
||||
for (i = 0; i < CMD_ARGC; ++i) {
|
||||
if (NULL != cmd_match) {
|
||||
else {
|
||||
cmd_match = strdup(CMD_ARGV[0]);
|
||||
|
||||
for (unsigned int i = 1; i < CMD_ARGC && cmd_match; ++i) {
|
||||
char *prev = cmd_match;
|
||||
|
||||
cmd_match = alloc_printf("%s %s", cmd_match, CMD_ARGV[i]);
|
||||
cmd_match = alloc_printf("%s %s", prev, CMD_ARGV[i]);
|
||||
free(prev);
|
||||
if (NULL == cmd_match) {
|
||||
LOG_ERROR("unable to build search string");
|
||||
return -ENOMEM;
|
||||
}
|
||||
} else {
|
||||
cmd_match = alloc_printf("%s", CMD_ARGV[i]);
|
||||
if (NULL == cmd_match) {
|
||||
LOG_ERROR("unable to build search string");
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
if (cmd_match == NULL) {
|
||||
LOG_ERROR("unable to build search string");
|
||||
return -ENOMEM;
|
||||
}
|
||||
retval = CALL_COMMAND_HANDLER(command_help_show_list,
|
||||
c, 0, full, cmd_match);
|
||||
|
||||
if (CMD_ARGC >= 1)
|
||||
free(cmd_match);
|
||||
return retval;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue