chiark / gitweb /
list: LIST_INSERT_BEFORE: update head if necessary (#4261)
authorMichael Olbrich <m.olbrich@pengutronix.de>
Tue, 4 Oct 2016 14:15:37 +0000 (16:15 +0200)
committerSven Eden <yamakuzure@gmx.net>
Wed, 5 Jul 2017 06:50:54 +0000 (08:50 +0200)
If the new item is inserted before the first item in the list, then the
head must be updated as well.
Add a test to the list unit test to check for this.

src/basic/list.h

index 5962aa42113b5d425cd181241a7f17da9ef43439..c3771a177f70e494b94d868a62056bc5d8f6e6be 100644 (file)
                 } else {                                                \
                         if ((_b->name##_prev = _a->name##_prev))        \
                                 _b->name##_prev->name##_next = _b;      \
                 } else {                                                \
                         if ((_b->name##_prev = _a->name##_prev))        \
                                 _b->name##_prev->name##_next = _b;      \
+                        else                                            \
+                                *_head = _b;                            \
                         _b->name##_next = _a;                           \
                         _a->name##_prev = _b;                           \
                 }                                                       \
                         _b->name##_next = _a;                           \
                         _a->name##_prev = _b;                           \
                 }                                                       \