From d1c16a0cc842a677cfe9609c9fe8b7094a073da7 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sun, 11 Jan 2026 13:21:09 +0100 Subject: [PATCH] spm/bs: use memmem when available Memmem is generally much more optimized. --- src/util-spm-bs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/util-spm-bs.c b/src/util-spm-bs.c index 76e05a972b..8848d95c72 100644 --- a/src/util-spm-bs.c +++ b/src/util-spm-bs.c @@ -37,6 +37,8 @@ * \brief Basic search improved. Limits are better handled, so * it doesn't start searches that wont fit in the remaining buffer * + * Use libc's memmem if available. + * * \param haystack pointer to the buffer to search in * \param haystack_len length limit of the buffer * \param needle pointer to the pattern we ar searching for @@ -47,7 +49,9 @@ uint8_t *BasicSearch(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *needle, uint16_t needle_len) { SCEnter(); - +#ifdef HAVE_MEMMEM + return memmem(haystack, haystack_len, needle, needle_len); +#else const uint8_t *h, *n; const uint8_t *hmax = haystack + haystack_len; const uint8_t *nmax = needle + needle_len; @@ -86,6 +90,7 @@ uint8_t *BasicSearch(const uint8_t *haystack, uint32_t haystack_len, const uint8 } SCReturnPtr(NULL, "uint8_t"); +#endif /* HAVE_MEMMEM */ } /**