]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
queue: add debug assertions to TAILQ
authorVictor Julien <victor@inliniac.net>
Wed, 11 Jan 2017 13:34:41 +0000 (14:34 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 17 Jan 2017 17:05:42 +0000 (18:05 +0100)
To avoid scan-build fp's add assertions that are only active if
built with scan-build.

src/queue.h

index 13455aa42905a0c5bdf8a12c700d5db0ff29f5c1..5e2a7b1366f43fa110eb032b3359f9488bcd52ff 100644 (file)
  * 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)