Index: include/asterisk/linkedlists.h =================================================================== --- include/asterisk/linkedlists.h (revision 10461) +++ include/asterisk/linkedlists.h (working copy) @@ -296,12 +296,13 @@ the \a current pointer without affecting the loop traversal. */ #define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field) { \ - typeof((head)->first) __list_next; \ typeof((head)->first) __list_prev = NULL; \ - for ((var) = (head)->first, __list_next = (var) ? (var)->field.next : NULL; \ - (var); \ - __list_prev = (var), (var) = __list_next, \ - __list_next = (var) ? (var)->field.next : NULL \ + typeof((head)->first) __list_cur = (head)->first; \ + for ((var) = (head)->first; \ + __list_prev ? __list_cur : (head)->first; \ + __list_prev = __list_cur, \ + __list_cur = __list_prev ? __list_prev->field.next : (head)->first,\ + (var) = __list_cur \ ) /*! @@ -317,11 +318,12 @@ */ #define AST_LIST_REMOVE_CURRENT(head, field) \ if (__list_prev) \ - __list_prev->field.next = __list_next; \ + __list_prev->field.next = __list_cur->field.next; \ else \ - (head)->first = __list_next; \ - if (!__list_next) \ - (head)->last = __list_prev; + (head)->first = __list_cur->field.next; \ + if (__list_cur->field.next == NULL) \ + (head)->last = __list_prev; \ + __list_cur = __list_prev; /*! \brief Inserts a list entry before the current entry during a traversal. @@ -336,11 +338,12 @@ #define AST_LIST_INSERT_BEFORE_CURRENT(head, elm, field) do { \ if (__list_prev) { \ (elm)->field.next = __list_prev->field.next; \ - __list_prev->field.next = elm; \ + __list_prev->field.next = (elm); \ } else { \ (elm)->field.next = (head)->first; \ (head)->first = (elm); \ - } \ + } \ + __list_prev = (elm); \ } while (0) /*!