Skip to content

Commit

Permalink
Fix TAILQ_REINIT (twitter#195)
Browse files Browse the repository at this point in the history
- replace hardcoded value with "field" to work as general solution
- fix setting last element *(head)->tqh_last = NULL; sets the first
element to NULL, set last element while traverse whole tailq
  • Loading branch information
michalbiesek authored and Yao Yue committed Jul 11, 2019
1 parent 4f5dbb0 commit 4846b15
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/cc_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,7 @@ struct { \

#define TAILQ_REINIT(head, var, field, offset) do { \
TAILQ_FIRST((head)) = var; \
*(head)->tqh_last = NULL; \
TAILQ_FOREACH(var, head, s_tqe) { \
TAILQ_FOREACH(var, head, field) { \
if ((TAILQ_NEXT((var), field)) != NULL) { \
TAILQ_NEXT((var), field) = \
(void *)((char *)(TAILQ_NEXT((var), field)) + (offset));\
Expand All @@ -706,6 +705,7 @@ struct { \
(var)->field.tqe_prev = \
(void *)((char *)((var)->field.tqe_prev) + (offset)); \
} \
(head)->tqh_last = &TAILQ_NEXT((var), field); \
} \
} while (0)

Expand Down

0 comments on commit 4846b15

Please sign in to comment.