From: Victor Julien Date: Wed, 11 Jan 2017 13:34:41 +0000 (+0100) Subject: queue: add debug assertions to TAILQ X-Git-Tag: suricata-3.2.1~69 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bbc02205fb8c398f2d9890254c209e52aea831fd;p=thirdparty%2Fsuricata.git queue: add debug assertions to TAILQ To avoid scan-build fp's add assertions that are only active if built with scan-build. --- diff --git a/src/queue.h b/src/queue.h index 13455aa429..5e2a7b1366 100644 --- a/src/queue.h +++ b/src/queue.h @@ -82,12 +82,18 @@ * For details on the use of these macros, see the queue(3) manual page. */ -#if defined(QUEUE_MACRO_DEBUG) || (defined(_KERNEL) && defined(DIAGNOSTIC)) +#if defined(__clang_analyzer__) || defined(QUEUE_MACRO_DEBUG) || (defined(_KERNEL) && defined(DIAGNOSTIC)) #define _Q_INVALIDATE(a) ((a) = ((void *)-1)) #else #define _Q_INVALIDATE(a) #endif +#if defined(__clang_analyzer__) +#define _Q_ASSERT(a) assert((a)) +#else +#define _Q_ASSERT(a) +#endif + /* * Singly-linked List definitions. */ @@ -377,9 +383,12 @@ struct { \ } while (0) #define TAILQ_INSERT_TAIL(head, elm, field) do { \ + _Q_ASSERT((elm)); \ + _Q_ASSERT((head)); \ (elm)->field.tqe_next = NULL; \ (elm)->field.tqe_prev = (head)->tqh_last; \ *(head)->tqh_last = (elm); \ + _Q_ASSERT(*(head)->tqh_last); \ (head)->tqh_last = &(elm)->field.tqe_next; \ } while (0) @@ -407,6 +416,7 @@ struct { \ else \ (head)->tqh_last = (elm)->field.tqe_prev; \ *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ + _Q_ASSERT((head)->tqh_first != (elm)); \ _Q_INVALIDATE((elm)->field.tqe_prev); \ _Q_INVALIDATE((elm)->field.tqe_next); \ } while (0)