From: Rafael Sadowski Subject: relayd: fix dead store To: tech@openbsd.org Date: Mon, 29 Dec 2025 10:44:47 +0100 First c is never used so check if carp_group_find is NULL and return. carp.c:64:7: warning: Although the value stored to 'c' is used in the enclosing expression, the value is never actually read from 'c' [deadcode.DeadSt ores] 64 | if ((c = carp_group_find(group)) == NULL) diff --git a/usr.sbin/relayd/carp.c b/usr.sbin/relayd/carp.c index 6a6a55a0fbb..34b6b6785a2 100644 --- a/usr.sbin/relayd/carp.c +++ b/usr.sbin/relayd/carp.c @@ -61,29 +61,31 @@ carp_demote_init(char *group, int force) struct carpgroup *c; int level; - if ((c = carp_group_find(group)) == NULL) { - if ((c = calloc(1, sizeof(struct carpgroup))) == NULL) { - log_warn("%s: calloc", __func__); - return (-1); - } - if ((c->group = strdup(group)) == NULL) { - log_warn("%s: strdup", __func__); - free(c); - return (-1); - } - - /* only demote if this group already is demoted */ - if ((level = carp_demote_get(group)) == -1) { - free(c->group); - free(c); - return (-1); - } - if (level > 0 || force) - c->do_demote = 1; - - TAILQ_INSERT_TAIL(&carpgroups, c, entry); + if (carp_group_find(group) == NULL) { + return (0); + } + + if ((c = calloc(1, sizeof(struct carpgroup))) == NULL) { + log_warn("%s: calloc", __func__); + return (-1); + } + if ((c->group = strdup(group)) == NULL) { + log_warn("%s: strdup", __func__); + free(c); + return (-1); } + /* only demote if this group already is demoted */ + if ((level = carp_demote_get(group)) == -1) { + free(c->group); + free(c); + return (-1); + } + if (level > 0 || force) + c->do_demote = 1; + + TAILQ_INSERT_TAIL(&carpgroups, c, entry); + return (0); }