summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2022-07-18 10:19:59 +0200
committerMaria Matejka <mq@ucw.cz>2022-07-18 10:19:59 +0200
commit636ab95f44efee774343f711ec46e69c6bea4e81 (patch)
tree6267dac5e8c14779f69d125c2a7ca7ee4907409c /lib
parent05673b16a87792baf8734dfcbf12ac2fd867f80b (diff)
parenta845651bc50b75b2be41b4427e04857ce3c106a6 (diff)
Merge commit 'a845651b' into thread-next
Diffstat (limited to 'lib')
-rw-r--r--lib/birdlib.h2
-rw-r--r--lib/lists.c13
2 files changed, 8 insertions, 7 deletions
diff --git a/lib/birdlib.h b/lib/birdlib.h
index 25545fc3..bdf69309 100644
--- a/lib/birdlib.h
+++ b/lib/birdlib.h
@@ -15,7 +15,7 @@
/* Ugly structure offset handling macros */
#define OFFSETOF(s, i) ((size_t) &((s *)0)->i)
-#define SKIP_BACK(s, i, p) ((s *)((char *)p - OFFSETOF(s, i)))
+#define SKIP_BACK(s, i, p) ({ s *_ptr = ((s *)((char *)p - OFFSETOF(s, i))); ASSERT_DIE(&_ptr->i == p); _ptr; })
#define BIRD_ALIGN(s, a) (((s)+a-1)&~(a-1))
#define CPU_STRUCT_ALIGN (MAX_(_Alignof(void*), _Alignof(u64)))
#define BIRD_CPU_ALIGN(s) BIRD_ALIGN((s), CPU_STRUCT_ALIGN)
diff --git a/lib/lists.c b/lib/lists.c
index 200576cf..1aa58085 100644
--- a/lib/lists.c
+++ b/lib/lists.c
@@ -35,11 +35,12 @@ check_list(list *l, node *n)
if (!l)
{
ASSERT_DIE(n);
- ASSERT_DIE(n->prev);
- do { n = n->prev; } while (n->prev);
+ node *nn = n;
+ while (nn->prev)
+ nn = nn->prev;
- l = SKIP_BACK(list, head_node, n);
+ l = SKIP_BACK(list, head_node, nn);
}
int seen = 0;
@@ -60,7 +61,7 @@ check_list(list *l, node *n)
}
ASSERT_DIE(cur == &(l->tail_node));
- ASSERT_DIE(!n || (seen == 1));
+ ASSERT_DIE(!n || (seen == 1) || (n == &l->head_node) || (n == &l->tail_node));
return 1;
}
@@ -120,7 +121,7 @@ add_head(list *l, node *n)
LIST_INLINE void
insert_node(node *n, node *after)
{
- EXPENSIVE_CHECK(check_list(l, after));
+ EXPENSIVE_CHECK(check_list(NULL, after));
ASSUME(n->prev == NULL);
ASSUME(n->next == NULL);
@@ -141,7 +142,7 @@ insert_node(node *n, node *after)
LIST_INLINE void
rem_node(node *n)
{
- EXPENSIVE_CHECK(check_list(NULL, n));
+ EXPENSIVE_CHECK((n == n->prev) && (n == n->next) || check_list(NULL, n));
node *z = n->prev;
node *x = n->next;