]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Correct AST_LIST_APPEND_LIST behavior when list to be appended is empty.
authorKevin P. Fleming <kpfleming@digium.com>
Wed, 17 Jun 2009 12:03:25 +0000 (12:03 +0000)
committerKevin P. Fleming <kpfleming@digium.com>
Wed, 17 Jun 2009 12:03:25 +0000 (12:03 +0000)
When the list to be appended is empty, and the list to be appended to is *not*,
AST_LIST_APPEND_LIST would actually cause the target list to become broken,
and no longer have a pointer to its last entry. This patch fixes the problem.

(reported by Stanislaw Pitucha on the asterisk-dev mailing list)

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@201261 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/linkedlists.h

index b78e7b0024665fe0596d06c43e4a92283016af43..f99001e7baa213c0830fdfca9c68e5ac8d899397 100644 (file)
@@ -691,15 +691,18 @@ struct {                                                          \
   calling this macro (the list entries are \b moved to the target list).
  */
 #define AST_LIST_APPEND_LIST(head, list, field) do {                   \
-      if (!(head)->first) {                                            \
+       if (!(list)->first) {                                           \
+               break;                                                  \
+       }                                                               \
+       if (!(head)->first) {                                           \
                (head)->first = (list)->first;                          \
                (head)->last = (list)->last;                            \
-      } else {                                                         \
+       } else {                                                        \
                (head)->last->field.next = (list)->first;               \
                (head)->last = (list)->last;                            \
-      }                                                                        \
-      (list)->first = NULL;                                            \
-      (list)->last = NULL;                                             \
+       }                                                               \
+       (list)->first = NULL;                                           \
+       (list)->last = NULL;                                            \
 } while (0)
 
 #define AST_RWLIST_APPEND_LIST AST_LIST_APPEND_LIST