From: claudio Date: Tue, 20 Apr 2021 08:03:12 +0000 (+0000) Subject: prefix_insert() and prefix_remove() emulate a tail queue by keeping the X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=43888d929630abefccd45a4fab1aa8d68b883abf;p=openbsd prefix_insert() and prefix_remove() emulate a tail queue by keeping the tail pointer (pointer to last element) around and depending on the state of the list insert at head or insert after tailp. Now gcc has a hard time to realize that the tail pointer is not used uninitalized. So rewrite the code to be more explicit about tailp handling (also rename the pointer to be more explicit). All in all this should be more readable and silences the gcc warning as well. --- diff --git a/usr.sbin/bgpd/rde_decide.c b/usr.sbin/bgpd/rde_decide.c index 9562c70c896..f842799a563 100644 --- a/usr.sbin/bgpd/rde_decide.c +++ b/usr.sbin/bgpd/rde_decide.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_decide.c,v 1.83 2021/03/08 12:18:46 claudio Exp $ */ +/* $OpenBSD: rde_decide.c,v 1.84 2021/04/20 08:03:12 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker @@ -295,7 +295,7 @@ void prefix_insert(struct prefix *new, struct prefix *ep, struct rib_entry *re) { struct prefix_list redo = LIST_HEAD_INITIALIZER(redo); - struct prefix *xp, *np, *rp, *ip = ep; + struct prefix *xp, *np, *tailp = NULL, *insertp = ep; int testall, selected = 0; /* start scan at the entry point (ep) or if the head if ep == NULL */ @@ -315,13 +315,13 @@ prefix_insert(struct prefix *new, struct prefix *ep, struct rib_entry *re) * put it onto redo queue. */ LIST_REMOVE(xp, entry.list.rib); - if (LIST_EMPTY(&redo)) + if (tailp == NULL) LIST_INSERT_HEAD(&redo, xp, entry.list.rib); else - LIST_INSERT_AFTER(rp, xp, + LIST_INSERT_AFTER(tailp, xp, entry.list.rib); - rp = xp; + tailp = xp; } else { /* * lock insertion point and @@ -340,14 +340,14 @@ prefix_insert(struct prefix *new, struct prefix *ep, struct rib_entry *re) if (testall == 2) selected = 0; if (!selected) - ip = xp; + insertp = xp; } } - if (ip == NULL) + if (insertp == NULL) LIST_INSERT_HEAD(&re->prefix_h, new, entry.list.rib); else - LIST_INSERT_AFTER(ip, new, entry.list.rib); + LIST_INSERT_AFTER(insertp, new, entry.list.rib); /* Fixup MED order again. All elements are < new */ while (!LIST_EMPTY(&redo)) { @@ -371,7 +371,7 @@ void prefix_remove(struct prefix *old, struct rib_entry *re) { struct prefix_list redo = LIST_HEAD_INITIALIZER(redo); - struct prefix *xp, *np, *rp; + struct prefix *xp, *np, *tailp = NULL; int testall; xp = LIST_NEXT(old, entry.list.rib); @@ -393,13 +393,13 @@ prefix_remove(struct prefix *old, struct rib_entry *re) * put it onto redo queue. */ LIST_REMOVE(xp, entry.list.rib); - if (LIST_EMPTY(&redo)) + if (tailp == NULL) LIST_INSERT_HEAD(&redo, xp, entry.list.rib); else - LIST_INSERT_AFTER(rp, xp, + LIST_INSERT_AFTER(tailp, xp, entry.list.rib); - rp = xp; + tailp = xp; } } }