X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Flist%2Flist.c;h=29dc30ba195876690eba54cac576336cb1461a41;hp=fad40cb80b3e00938ead3ecbe96c415c55a3973d;hb=ac9d55d8c5af9697be8c4dd4f27de61e3cb8bf95;hpb=22ffb884ca6a5f16517e49e051d8fb5a22e5049d diff --git a/ccan/list/list.c b/ccan/list/list.c index fad40cb8..29dc30ba 100644 --- a/ccan/list/list.c +++ b/ccan/list/list.c @@ -1,7 +1,22 @@ +/* Licensed under LGPLv2.1+ - see LICENSE file for details */ #include #include #include "list.h" +static void *corrupt(const char *abortstr, + const struct list_node *head, + const struct list_node *node, + unsigned int count) +{ + if (abortstr) { + fprintf(stderr, + "%s: prev corrupt in node %p (%u) of %p\n", + abortstr, node, count, head); + abort(); + } + return NULL; +} + struct list_node *list_check_node(const struct list_node *node, const char *abortstr) { @@ -10,31 +25,18 @@ struct list_node *list_check_node(const struct list_node *node, for (p = node, n = node->next; n != node; p = n, n = n->next) { count++; - if (n->prev != p) { - if (!abortstr) - return NULL; - fprintf(stderr, - "%s: prev corrupt in node %p (%u) of %p\n", - abortstr, n, count, node); - abort(); - } + if (n->prev != p) + return corrupt(abortstr, node, n, count); } + /* Check prev on head node. */ + if (node->prev != p) + return corrupt(abortstr, node, node, 0); + return (struct list_node *)node; } struct list_head *list_check(const struct list_head *h, const char *abortstr) { - if (h->n.next == &h->n) { - if (h->n.prev != &h->n) { - if (!abortstr) - return NULL; - fprintf(stderr, "%s: prev corrupt in empty %p\n", - abortstr, h); - abort(); - } - return (struct list_head *)h; - } - if (!list_check_node(&h->n, abortstr)) return NULL; return (struct list_head *)h;