queue.h: suppress scan-build warnings

If running under scan-build, use our own implementations of all
the macros which include some code to satisfy scan-build
warnings.
pull/6478/head
Jason Ish 4 years ago committed by Victor Julien
parent 77604d86d6
commit 07370ed5c0

@ -51,19 +51,14 @@
#include "autoconf.h" #include "autoconf.h"
#ifdef HAVE_SYS_QUEUE_H #if defined(HAVE_SYS_QUEUE_H) && !defined(__clang_analyzer__)
#include <sys/queue.h> #include <sys/queue.h>
#endif #endif
/* Not included in Linux, but are in FreeBSD and friends. #if defined(__clang_analyzer__)
* #define _Q_ASSERT(a) assert((a))
* This implementation from FreeBSD's sys/queue.h. #else
*/ #define _Q_ASSERT(a)
#ifndef TAILQ_FOREACH_SAFE
#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = TAILQ_FIRST((head)); \
(var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
(var) = (tvar))
#endif #endif
/* The BSDs have removed CIRCLEQ but it still exists in Linux. /* The BSDs have removed CIRCLEQ but it still exists in Linux.
@ -225,7 +220,8 @@ struct { \
* Complete TAILQ implementation as sys/queue.h is not available on Windows * Complete TAILQ implementation as sys/queue.h is not available on Windows
* and used by Suricata. * and used by Suricata.
* *
* This implementation copied from FreeBSD sys/queue.h. * This implementation copied from FreeBSD sys/queue.h with the addition
* of our _Q_ASSERT macros to satisy scan-build.
*/ */
#ifndef TAILQ_HEAD #ifndef TAILQ_HEAD
@ -297,9 +293,12 @@ struct { \
} while (0) } while (0)
#define TAILQ_INSERT_TAIL(head, elm, field) do { \ #define TAILQ_INSERT_TAIL(head, elm, field) do { \
_Q_ASSERT((elm)); \
_Q_ASSERT((head)); \
TAILQ_NEXT((elm), field) = NULL; \ TAILQ_NEXT((elm), field) = NULL; \
(elm)->field.tqe_prev = (head)->tqh_last; \ (elm)->field.tqe_prev = (head)->tqh_last; \
*(head)->tqh_last = (elm); \ *(head)->tqh_last = (elm); \
_Q_ASSERT(*(head)->tqh_last); \
(head)->tqh_last = &TAILQ_NEXT((elm), field); \ (head)->tqh_last = &TAILQ_NEXT((elm), field); \
} while (0) } while (0)
@ -317,9 +316,21 @@ struct { \
(elm)->field.tqe_prev; \ (elm)->field.tqe_prev; \
else \ else \
(head)->tqh_last = (elm)->field.tqe_prev; \ (head)->tqh_last = (elm)->field.tqe_prev; \
_Q_ASSERT((head)->tqh_first != (elm)); \
*(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \ *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \
} while (0) } while (0)
#endif /* !TAILQ_HEAD */ #endif /* !TAILQ_HEAD */
/* Not included in Linux, but are in FreeBSD and friends.
*
* This implementation from FreeBSD's sys/queue.h.
*/
#ifndef TAILQ_FOREACH_SAFE
#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = TAILQ_FIRST((head)); \
(var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
(var) = (tvar))
#endif
#endif /* !SURICATA_QUEUE_H */ #endif /* !SURICATA_QUEUE_H */

Loading…
Cancel
Save