X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Flist%2Flist.c;h=fad40cb80b3e00938ead3ecbe96c415c55a3973d;hp=0a9e4e4d2d5d092ef1449b82c4a72781033fadc9;hb=a04a5f7472bd8146936864702084e533d474eea4;hpb=a8b248ea9de55316cac4423a99a727ca7b54e0fc diff --git a/ccan/list/list.c b/ccan/list/list.c index 0a9e4e4d..fad40cb8 100644 --- a/ccan/list/list.c +++ b/ccan/list/list.c @@ -2,32 +2,40 @@ #include #include "list.h" -struct list_head *list_check(struct list_head *h, const char *abortstr) +struct list_node *list_check_node(const struct list_node *node, + const char *abortstr) { - struct list_node *n, *p; + const struct list_node *p, *n; int count = 0; - if (h->n.next == &h->n) { - if (h->n.prev != &h->n) { + 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 empty %p\n", - abortstr, h); + fprintf(stderr, + "%s: prev corrupt in node %p (%u) of %p\n", + abortstr, n, count, node); abort(); } - return h; } + return (struct list_node *)node; +} - for (p = &h->n, n = h->n.next; n != &h->n; p = n, n = n->next) { - count++; - if (n->prev != p) { +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 node %p (%u) of %p\n", - abortstr, n, count, h); + fprintf(stderr, "%s: prev corrupt in empty %p\n", + abortstr, h); abort(); } + return (struct list_head *)h; } - return h; + + if (!list_check_node(&h->n, abortstr)) + return NULL; + return (struct list_head *)h; }