From: Ondřej Surý Date: Tue, 18 Oct 2022 09:28:03 +0000 (+0200) Subject: Replace (void *)-1 with ISC_LINK_TOMBSTONE X-Git-Tag: v9.19.7~52^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5e20c2ccfb3a2aaad6ead581a1801e6289a00e5d;p=thirdparty%2Fbind9.git Replace (void *)-1 with ISC_LINK_TOMBSTONE Instead of having "arbitrary" (void *)-1 to define non-linked, add a ISC_LINK_TOMBSTONE(type) macro that replaces the "magic" value with a define. --- diff --git a/lib/isc/include/isc/list.h b/lib/isc/include/isc/list.h index 007cec0f30d..2cf4437542d 100644 --- a/lib/isc/include/isc/list.h +++ b/lib/isc/include/isc/list.h @@ -15,13 +15,16 @@ #include +#define ISC_LINK_TOMBSTONE(type) ((type *)-1) + #define ISC_LIST_INITIALIZER \ { \ .head = NULL, .tail = NULL, \ } -#define ISC_LINK_INITIALIZER_TYPE(type) \ - { \ - .prev = (type *)-1, .next = (type *)-1, \ +#define ISC_LINK_INITIALIZER_TYPE(type) \ + { \ + .prev = ISC_LINK_TOMBSTONE(type), \ + .next = ISC_LINK_TOMBSTONE(type), \ } #define ISC_LINK_INITIALIZER ISC_LINK_INITIALIZER_TYPE(void) @@ -45,13 +48,15 @@ struct { \ type *prev, *next; \ } -#define ISC_LINK_INIT_TYPE(elt, link, type) \ - do { \ - (elt)->link.prev = (type *)(-1); \ - (elt)->link.next = (type *)(-1); \ +#define ISC_LINK_INIT_TYPE(elt, link, type) \ + do { \ + (elt)->link.prev = ISC_LINK_TOMBSTONE(type); \ + (elt)->link.next = ISC_LINK_TOMBSTONE(type); \ } while (0) -#define ISC_LINK_INIT(elt, link) ISC_LINK_INIT_TYPE(elt, link, void) -#define ISC_LINK_LINKED(elt, link) ((void *)((elt)->link.prev) != (void *)(-1)) +#define ISC_LINK_INIT(elt, link) ISC_LINK_INIT_TYPE(elt, link, void) +#define ISC_LINK_LINKED_TYPE(elt, link, type) \ + ((type *)((elt)->link.prev) != ISC_LINK_TOMBSTONE(type)) +#define ISC_LINK_LINKED(elt, link) ISC_LINK_LINKED_TYPE(elt, link, void) #define ISC_LIST_HEAD(list) ((list).head) #define ISC_LIST_TAIL(list) ((list).tail) @@ -113,8 +118,8 @@ ISC_INSIST((list).head == (elt)); \ (list).head = (elt)->link.next; \ } \ - (elt)->link.prev = (type *)(-1); \ - (elt)->link.next = (type *)(-1); \ + (elt)->link.prev = ISC_LINK_TOMBSTONE(type); \ + (elt)->link.next = ISC_LINK_TOMBSTONE(type); \ ISC_INSIST((list).head != (elt)); \ ISC_INSIST((list).tail != (elt)); \ } while (0)