From 410acf226fd94890eb1a657f4c4dfa33015ca0d3 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sat, 15 Oct 2022 16:10:22 +0200 Subject: [PATCH] detect: unittest guards for ut only function --- src/detect-engine-alert.c | 9 ++++----- src/detect-engine-alert.h | 2 ++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/detect-engine-alert.c b/src/detect-engine-alert.c index 2a4353670d..45db57b957 100644 --- a/src/detect-engine-alert.c +++ b/src/detect-engine-alert.c @@ -126,6 +126,7 @@ static int PacketAlertHandle(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det SCReturnInt(1); } +#ifdef UNITTESTS /** * \brief Check if a certain sid alerted, this is used in the test functions * @@ -136,19 +137,17 @@ static int PacketAlertHandle(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det */ int PacketAlertCheck(Packet *p, uint32_t sid) { - uint16_t i = 0; int match = 0; - for (i = 0; i < p->alerts.cnt; i++) { - if (p->alerts.alerts[i].s == NULL) - continue; - + for (uint16_t i = 0; i < p->alerts.cnt; i++) { + BUG_ON(p->alerts.alerts[i].s == NULL); if (p->alerts.alerts[i].s->id == sid) match++; } return match; } +#endif static inline void RuleActionToFlow(const uint8_t action, Flow *f) { diff --git a/src/detect-engine-alert.h b/src/detect-engine-alert.h index 14f5b72ae2..984f0c3228 100644 --- a/src/detect-engine-alert.h +++ b/src/detect-engine-alert.h @@ -33,7 +33,9 @@ void AlertQueueFree(DetectEngineThreadCtx *det_ctx); void AlertQueueAppend(DetectEngineThreadCtx *det_ctx, const Signature *s, Packet *p, uint64_t tx_id, uint8_t alert_flags); void PacketAlertFinalize(DetectEngineCtx *, DetectEngineThreadCtx *, Packet *); +#ifdef UNITTESTS int PacketAlertCheck(Packet *, uint32_t); +#endif void PacketAlertTagInit(void); void DetectEngineAlertRegisterTests(void);