]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
client: make it easier for Coverity to understand commands_new()
authorVincent Bernat <vincent@bernat.ch>
Sun, 21 Mar 2021 12:56:19 +0000 (13:56 +0100)
committerVincent Bernat <vincent@bernat.ch>
Sun, 21 Mar 2021 12:56:19 +0000 (13:56 +0100)
Never returning NULL is not enough to make Coverity understands we
don't leak anything. Remove the branch in commands_new() as it must
never happen, except for the root node.

src/client/commands.c

index 7e35ecb15c6e6be742b1e433596ba923109d571d..823176792a9015d5c09baf24f9cc9f996863b0d1 100644 (file)
@@ -99,7 +99,10 @@ struct cmd_node {
 struct cmd_node*
 commands_root(void)
 {
-       return commands_new(NULL, NULL, NULL, NULL, NULL, NULL);
+       struct cmd_node *new = calloc(1, sizeof(struct cmd_node));
+       if (new == NULL) fatalx("lldpctl", "out of memory");
+       TAILQ_INIT(&new->subentries);
+       return new;
 }
 
 /**
@@ -175,8 +178,7 @@ commands_new(struct cmd_node *root,
        new->execute = execute;
        new->arg = arg;
        TAILQ_INIT(&new->subentries);
-       if (root != NULL)
-               TAILQ_INSERT_TAIL(&root->subentries, new, next);
+       TAILQ_INSERT_TAIL(&root->subentries, new, next);
        return new;
 }