integrity p4
This commit is contained in:
parent
11a96bdb6e
commit
031c9e2a6b
47
include/sl.h
47
include/sl.h
|
@ -227,8 +227,8 @@
|
|||
* return cmp(list, a, b, aux);
|
||||
* }
|
||||
*/
|
||||
#define SKIP_COMPARATOR(list, type, fn_blk) \
|
||||
int __skip_cmp_##type(struct list *head, struct type *a, struct type *b, void *aux) \
|
||||
#define SKIP_COMPARATOR(list, decl, fn_blk) \
|
||||
int __skip_cmp_##decl(struct list *head, struct decl *a, struct decl *b, void *aux) \
|
||||
{ \
|
||||
if (a == b) \
|
||||
return 0; \
|
||||
|
@ -996,10 +996,9 @@
|
|||
/* -- __skip_integrity_check_ */ \
|
||||
static int __skip_integrity_check_##decl(decl##_t *slist, int flags) \
|
||||
{ \
|
||||
size_t size; \
|
||||
unsigned nth, n_err = 0; \
|
||||
decl##_node_t *node; \
|
||||
struct __skiplist_##decl_idx *this, *that, *prev, *next; \
|
||||
decl##_node_t *node, *prev, *next; \
|
||||
struct __skiplist_##decl_idx *this; \
|
||||
\
|
||||
if (slist == NULL) { \
|
||||
__skip_integrity_failure_##decl("slist was NULL, nothing to check"); \
|
||||
|
@ -1095,12 +1094,11 @@
|
|||
\
|
||||
/* Validate each node */ \
|
||||
nth = 0; \
|
||||
size = prefix##skip_size_##decl(slist); \
|
||||
node = prefix##skip_head_##decl(slist); \
|
||||
while (node) { \
|
||||
this = &node->field.sle; \
|
||||
if (this->next == NULL) { \
|
||||
__skip_integrity_failure_##decl("the %u node's [%p] next field should never NULL", nth, (void *)node); \
|
||||
__skip_integrity_failure_##decl("the %uth node's [%p] next field should never NULL", nth, (void *)node); \
|
||||
n_err++; \
|
||||
if (flags) \
|
||||
return n_err; \
|
||||
|
@ -1114,12 +1112,43 @@
|
|||
uintptr_t a = (uintptr_t)this->next; \
|
||||
uintptr_t b = (intptr_t)((uintptr_t)node + sizeof(decl##_node_t)); \
|
||||
if (a != b) { \
|
||||
__skip_integrity_failure_##decl("the %u node's [%p] next field isn't at the proper offset relative to the node", nth, (void *)node); \
|
||||
__skip_integrity_failure_##decl("the %uth node's [%p] next field isn't at the proper offset relative to the node", nth, (void *)node); \
|
||||
n_err++; \
|
||||
if (flags) \
|
||||
return n_err; \
|
||||
} \
|
||||
next = this->next[0]; \
|
||||
prev = this->prev; \
|
||||
if (__skip_key_compare_##decl(slist, node, node, slist->aux) != 0) { \
|
||||
__skip_integrity_failure_##decl("the %uth node [%p] is not equal to itself", nth, (void *)node); \
|
||||
n_err++; \
|
||||
if (flags) \
|
||||
return n_err; \
|
||||
} \
|
||||
if (__skip_key_compare_##decl(slist, node, prev, slist->aux) < 0) { \
|
||||
__skip_integrity_failure_##decl("the %uth node [%p] is not greater than the prev node [%p]", nth, (void *)node, (void *)prev); \
|
||||
n_err++; \
|
||||
if (flags) \
|
||||
return n_err; \
|
||||
} \
|
||||
if (__skip_key_compare_##decl(slist, node, next, slist->aux) > 0) { \
|
||||
__skip_integrity_failure_##decl("the %uth node [%p] is not less than the next node [%p]", nth, (void *)node, (void *)next); \
|
||||
n_err++; \
|
||||
if (flags) \
|
||||
return n_err; \
|
||||
} \
|
||||
if (__skip_key_compare_##decl(slist, prev, node, slist->aux) > 0) { \
|
||||
__skip_integrity_failure_##decl("the prev node [%p] is not less than the %uth node [%p]", (void *)prev, nth, (void *)node); \
|
||||
n_err++; \
|
||||
if (flags) \
|
||||
return n_err; \
|
||||
} \
|
||||
if (__skip_key_compare_##decl(slist, next, node, slist->aux) < 0) { \
|
||||
__skip_integrity_failure_##decl("the next node [%p] is not greater than the %uth node [%p]", (void *)next, nth, (void *)node); \
|
||||
n_err++; \
|
||||
if (flags) \
|
||||
return n_err; \
|
||||
} \
|
||||
\
|
||||
node = prefix##skip_next_node_##decl(slist, node); \
|
||||
nth++; \
|
||||
} \
|
||||
|
|
Loading…
Reference in a new issue