NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

misc/47929: macro CIRCLEQ_REPLACE in queue.h is incorrect



>Number:         47929
>Category:       misc
>Synopsis:       macro CIRCLEQ_REPLACE in queue.h is incorrect
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    misc-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jun 14 20:20:00 +0000 2013
>Originator:     Michael Piszczek
>Release:        
>Organization:
Datadirect Networks
>Environment:
>Description:
I believe the macro CIRCLEQ_REPLACE in queue.h is incorrect.
The macro should be using a pointer to head. Otherwise CIRCLEQ_END(head) will 
not be correct.
Please see the diff below.

--- a/src/sys/sys/queue.h
+++ b/src/sys/sys/queue.h
@@ -560,12 +560,12 @@ struct {                                         \
 #define CIRCLEQ_REPLACE(head, elm, elm2, field) do {                  \
        if (((elm2)->field.cqe_next = (elm)->field.cqe_next) ==        \
            CIRCLEQ_END(head))                                         \
-               (head).cqh_last = (elm2);                              \
+               (head)->cqh_last = (elm2);                             \
        else                                                           \
                (elm2)->field.cqe_next->field.cqe_prev = (elm2);       \
        if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) ==        \
            CIRCLEQ_END(head))                                         \
-               (head).cqh_first = (elm2);                             \
+               (head)->cqh_first = (elm2);                            \
        else                                                           \
                (elm2)->field.cqe_prev->field.cqe_next = (elm2);       \
        _Q_INVALIDATE((elm)->field.cqe_prev);             
>How-To-Repeat:

>Fix:
#define CIRCLEQ_REPLACE(head, elm, elm2, field) do {                    \
        if (((elm2)->field.cqe_next = (elm)->field.cqe_next) ==         \
            CIRCLEQ_END(head))                                          \
                (head)->cqh_last = (elm2);                              \
        else                                                            \
                (elm2)->field.cqe_next->field.cqe_prev = (elm2);        \
        if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) ==         \
            CIRCLEQ_END(head))                                          \
                (head)->cqh_first = (elm2);                             \
        else                                                            \
                (elm2)->field.cqe_prev->field.cqe_next = (elm2);        \
        _Q_INVALIDATE((elm)->field.cqe_prev);                           \
        _Q_INVALIDATE((elm)->field.cqe_next);                           \
} while (0)



Home | Main Index | Thread Index | Old Index