summaryrefslogtreecommitdiff
path: root/lib/lists.h
diff options
context:
space:
mode:
authorJan Moskyto Matejka <mq@ucw.cz>2016-03-23 01:45:37 +0100
committerOndrej Zajicek (work) <santiago@crfreenet.org>2016-03-23 02:21:42 +0100
commit54bb032d21d25a2221877e15325e79add10278ec (patch)
treecf5fbb8388001ef2a9af3a55548f612264ef64ea /lib/lists.h
parent665b8e5283df4f64eb44d8fb434489be1474b5d4 (diff)
Birdlib: Modify lists to avoid problems with pointer aliasing rules
The old linked list implementation used some wild typecasts and required GCC option -fno-strict-aliasing to work properly. This patch fixes that. However, we still keep the option due to other potential problems. (Commited by Ondrej Santiago Zajicek)
Diffstat (limited to 'lib/lists.h')
-rw-r--r--lib/lists.h17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/lists.h b/lib/lists.h
index 4204cbc5..51856b05 100644
--- a/lib/lists.h
+++ b/lib/lists.h
@@ -26,10 +26,23 @@ typedef struct node {
struct node *next, *prev;
} node;
-typedef struct list { /* In fact two overlayed nodes */
- struct node *head, *null, *tail;
+typedef union list { /* In fact two overlayed nodes */
+ struct { /* Head node */
+ struct node head_node;
+ void *head_padding;
+ };
+ struct { /* Tail node */
+ void *tail_padding;
+ struct node tail_node;
+ };
+ struct { /* Split to separate pointers */
+ struct node *head;
+ struct node *null;
+ struct node *tail;
+ };
} list;
+
#define NODE (node *)
#define HEAD(list) ((void *)((list).head))
#define TAIL(list) ((void *)((list).tail))