]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: lists: Handle 1-element-lists in MT_LIST_BEHEAD().
authorOlivier Houchard <ohouchard@haproxy.com>
Thu, 17 Oct 2019 15:46:01 +0000 (17:46 +0200)
committerOlivier Houchard <cognet@ci0.org>
Thu, 17 Oct 2019 15:48:20 +0000 (17:48 +0200)
In MT_LIST_BEHEAD(), explicitely set the next element of the prev to NULL,
instead of setting it to the prev of the next. If we only had one element,
then we'd set the next and the prev to the element itself, and thus it would
make the element appear to be outside any list.

include/common/mini-clist.h

index bb794e3d6b8b2bdd6f3334ec51819ca5d38366b9..e29451148cad94bea8d5e2591802313fe00d079d 100644 (file)
@@ -307,6 +307,8 @@ struct cond_wordlist {
  * and the list is closed. If the list was empty, NULL is returned. This may
  * exclusively be used with lists modified by MT_LIST_ADD/MT_LIST_ADDQ. This
  * is incompatible with MT_LIST_DEL run concurrently.
+ * If there's at least one element, the next of the last element will always
+ * be NULL.
  */
 #define MT_LIST_BEHEAD(_lh) ({                                      \
         struct mt_list *lh = (_lh);                                 \
@@ -336,7 +338,7 @@ struct cond_wordlist {
                (lh)->next = (lh);                                  \
                (lh)->prev = (lh);                                  \
                _n->prev = _p;                                      \
-               _p->next = _n;                                      \
+               _p->next = NULL;                                    \
                __ha_barrier_store();                               \
                break;                                              \
        }                                                           \