X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Flist%2Flist.c;h=fad40cb80b3e00938ead3ecbe96c415c55a3973d;hp=3d5811011bcc1e034dc1571a622162e8bbfeede6;hb=22ffb884ca6a5f16517e49e051d8fb5a22e5049d;hpb=1f4312c3320f353a18ab4aec4b8ae725fc25c911 diff --git a/ccan/list/list.c b/ccan/list/list.c index 3d581101..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(const struct list_head *h, const char *abortstr) +struct list_node *list_check_node(const struct list_node *node, + const char *abortstr) { - const 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 (struct list_head *)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; } + + if (!list_check_node(&h->n, abortstr)) + return NULL; return (struct list_head *)h; }