helper/command: fix clang static analyzer warning 04/5904/2
authorTomas Vanek <vanekt@fbl.cz>
Thu, 29 Oct 2020 17:32:13 +0000 (18:32 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Wed, 4 Nov 2020 17:35:14 +0000 (17:35 +0000)
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>
src/helper/command.c

index 271e7b993fb46355c191953ac9cec0ce46c52587..773195e2f4522ed70fb4b81a07318a5d3095ccdd 100644 (file)
@@ -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;
 }
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)