39 static const uint8_t *SCMemimem(
const uint8_t *haystack, uint32_t haystack_len,
40 const uint8_t *needle,
const uint32_t needle_len)
42 if (needle_len > haystack_len)
44 uint32_t slice_size =
MAX(
MIN(haystack_len, 128), needle_len * 3);
45 uint8_t slice[slice_size];
48 const uint32_t size =
MIN(haystack_len - o, slice_size);
49 MemcpyToLower(slice, haystack + o, size);
50 uint8_t *found = memmem(slice, size, needle, needle_len);
52 size_t slice_offset = found - slice;
53 return haystack + (o + slice_offset);
55 o += (size - (needle_len - 1));
56 }
while (o + needle_len <= haystack_len);
61 uint32_t haystack_len)
63 const SpmMmCtx *sctx =
ctx->ctx;
66 return (uint8_t *)SCMemimem(haystack, haystack_len, sctx->needle, sctx->needle_len);
68 return memmem(haystack, haystack_len, sctx->needle, sctx->needle_len);
72 static SpmCtx *MMInitCtx(
const uint8_t *needle, uint16_t needle_len,
int nocase,
81 SpmMmCtx *sctx =
SCCalloc(1,
sizeof(SpmMmCtx) + needle_len);
87 sctx->nocase = nocase;
88 sctx->needle_len = needle_len;
90 MemcpyToLower(sctx->needle, needle, needle_len);
92 memcpy(sctx->needle, needle, needle_len);
105 SpmMmCtx *sctx =
ctx->ctx;
116 if (global_thread_ctx == NULL) {
121 return global_thread_ctx;
126 if (global_thread_ctx == NULL) {
129 SCFree(global_thread_ctx);
132 static void MMDestroyThreadCtx(
SpmThreadCtx *thread_ctx)
134 if (thread_ctx == NULL) {
143 if (thread_ctx == NULL) {