[prev in list] [next in list] [prev in thread] [next in thread]
List: openocd-development
Subject: [OpenOCD-devel] [PATCH]: c2d9c94 helper/command: fix clang static analyzer warning
From: gerrit () openocd ! org (gerrit)
Date: 2020-10-29 19:54:32
Message-ID: 20201029195432.4939C4A01C0 () mail ! openocd ! org
[Download RAW message or body]
This is an automated email from Gerrit.
Tomas Vanek (vanekt@fbl.cz) just uploaded a new patch set to Gerrit, which you can \
find at http://openocd.zylin.com/5904
-- gerrit
commit c2d9c94c7528366dacef85bd403e5a2d2e7c49b0
Author: Tomas Vanek <vanekt@fbl.cz>
Date: Thu Oct 29 18:32:13 2020 +0100
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>
diff --git a/src/helper/command.c b/src/helper/command.c
index 271e7b9..773195e 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -920,39 +920,29 @@ COMMAND_HANDLER(handle_help_command)
bool full = strcmp(CMD_NAME, "help") == 0;
int retval;
struct command *c = CMD_CTX->commands;
- char *cmd_match = NULL;
-
- if (CMD_ARGC == 0)
- cmd_match = "";
- else if (CMD_ARGC >= 1) {
- unsigned i;
-
- for (i = 0; i < CMD_ARGC; ++i) {
- if (NULL != cmd_match) {
- char *prev = cmd_match;
-
- cmd_match = alloc_printf("%s %s", cmd_match, 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;
- }
- }
+ char *cmd_match;
+
+ if (CMD_ARGC <= 0)
+ cmd_match = strdup("");
+
+ 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", prev, CMD_ARGV[i]);
+ free(prev);
}
- } 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);
+ free(cmd_match);
return retval;
}
--
_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic