From: Anoop Saldanha Date: Thu, 22 Mar 2012 11:45:15 +0000 (+0530) Subject: update all spm algos to use 16 bit pattern lengths. Should compress a lot of tables X-Git-Tag: suricata-1.3beta1~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d192a688138ede3c4d7309a24ab839093096f96;p=thirdparty%2Fsuricata.git update all spm algos to use 16 bit pattern lengths. Should compress a lot of tables --- diff --git a/src/suricata.c b/src/suricata.c index 9459f376a5..794259ce5d 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -181,6 +181,7 @@ #include "util-mem.h" #include "util-memcmp.h" #include "util-proto-name.h" +#include "util-spm-bm.h" /* * we put this here, because we only use it here in main. diff --git a/src/util-spm-bm.c b/src/util-spm-bm.c index e4c3bffeea..b4aa11d2cd 100644 --- a/src/util-spm-bm.c +++ b/src/util-spm-bm.c @@ -45,7 +45,7 @@ * \param str pointer to the pattern string * \param size length of the string */ -void BoyerMooreCtxToNocase(BmCtx *bm_ctx, uint8_t *needle, uint32_t needle_len) { +void BoyerMooreCtxToNocase(BmCtx *bm_ctx, uint8_t *needle, uint16_t needle_len) { /* Prepare bad chars with nocase chars */ PreBmBcNocase(needle, needle_len, bm_ctx->bmBc); @@ -62,7 +62,7 @@ void BoyerMooreCtxToNocase(BmCtx *bm_ctx, uint8_t *needle, uint32_t needle_len) * \retval BmCtx pointer to the newly created Context for the pattern * \initonly BoyerMoore contexts should be created at init */ -BmCtx *BoyerMooreCtxInit(uint8_t *needle, uint32_t needle_len) { +BmCtx *BoyerMooreCtxInit(uint8_t *needle, uint16_t needle_len) { BmCtx *new = SCMalloc(sizeof(BmCtx)); if (new == NULL) { SCLogError(SC_ERR_FATAL, "Fatal error encountered in BoyerMooreCtxInit. Exiting..."); @@ -72,7 +72,7 @@ BmCtx *BoyerMooreCtxInit(uint8_t *needle, uint32_t needle_len) { /* Prepare bad chars */ PreBmBc(needle, needle_len, new->bmBc); - new->bmGs = SCMalloc(sizeof(int32_t) * (needle_len + 1)); + new->bmGs = SCMalloc(sizeof(uint16_t) * (needle_len + 1)); if (new->bmGs == NULL) { exit(EXIT_FAILURE); } @@ -113,7 +113,7 @@ void BoyerMooreCtxDeInit(BmCtx *bmctx) * \param size length of the string * \param result pointer to an empty array that will hold the badchars */ -void PreBmBc(const uint8_t *x, int32_t m, int32_t *bmBc) { +void PreBmBc(const uint8_t *x, uint16_t m, uint16_t *bmBc) { int32_t i; for (i = 0; i < 256; ++i) { @@ -131,7 +131,7 @@ void PreBmBc(const uint8_t *x, int32_t m, int32_t *bmBc) { * \param m length of the string * \param suff pointer to an empty array that will hold the prefixes (shifts) */ -void BoyerMooreSuffixes(const uint8_t *x, int32_t m, int32_t *suff) { +void BoyerMooreSuffixes(const uint8_t *x, uint16_t m, uint16_t *suff) { int32_t f = 0, g, i; suff[m - 1] = m; g = m - 1; @@ -157,11 +157,11 @@ void BoyerMooreSuffixes(const uint8_t *x, int32_t m, int32_t *suff) { * \param bmGs pointer to an empty array that will hold the prefixes (shifts) * \retval 0 ok, -1 failed */ -int PreBmGs(const uint8_t *x, int32_t m, int32_t *bmGs) { +int PreBmGs(const uint8_t *x, uint16_t m, uint16_t *bmGs) { int32_t i, j; - int32_t *suff; + uint16_t *suff; - suff = SCMalloc(sizeof(int32_t) * (m + 1)); + suff = SCMalloc(sizeof(uint16_t) * (m + 1)); if (suff == NULL) return -1; @@ -192,7 +192,7 @@ int PreBmGs(const uint8_t *x, int32_t m, int32_t *bmGs) { * \param size length of the string * \param result pointer to an empty array that will hold the badchars */ -void PreBmBcNocase(const uint8_t *x, int32_t m, int32_t *bmBc) { +void PreBmBcNocase(const uint8_t *x, uint16_t m, uint16_t *bmBc) { int32_t i; for (i = 0; i < 256; ++i) { @@ -203,7 +203,7 @@ void PreBmBcNocase(const uint8_t *x, int32_t m, int32_t *bmBc) { } } -void BoyerMooreSuffixesNocase(const uint8_t *x, int32_t m, int32_t *suff) { +void BoyerMooreSuffixesNocase(const uint8_t *x, uint16_t m, uint16_t *suff) { int32_t f = 0, g, i; suff[m - 1] = m; @@ -232,11 +232,11 @@ void BoyerMooreSuffixesNocase(const uint8_t *x, int32_t m, int32_t *suff) { * \param m length of the string * \param bmGs pointer to an empty array that will hold the prefixes (shifts) */ -void PreBmGsNocase(const uint8_t *x, int32_t m, int32_t *bmGs) { +void PreBmGsNocase(const uint8_t *x, uint16_t m, uint16_t *bmGs) { int32_t i, j; - int32_t* suff; + uint16_t* suff; - suff = SCMalloc(sizeof(int32_t) * (m + 1)); + suff = SCMalloc(sizeof(uint16_t) * (m + 1)); if (suff == NULL) return; @@ -277,7 +277,7 @@ void PreBmGsNocase(const uint8_t *x, int32_t m, int32_t *bmGs) { * * \retval ptr to start of the match; NULL if no match */ -uint8_t *BoyerMoore(uint8_t *x, int32_t m, uint8_t *y, int32_t n, int32_t *bmGs, int32_t *bmBc) { +uint8_t *BoyerMoore(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, uint16_t *bmGs, uint16_t *bmBc) { int i, j, m1, m2; #if 0 printf("\nBad:\n"); @@ -290,6 +290,7 @@ uint8_t *BoyerMoore(uint8_t *x, int32_t m, uint8_t *y, int32_t n, int32_t *bmGs, printf("\n"); #endif j = 0; + while (j <= n - m ) { for (i = m - 1; i >= 0 && x[i] == y[i + j]; --i); @@ -321,7 +322,7 @@ uint8_t *BoyerMoore(uint8_t *x, int32_t m, uint8_t *y, int32_t n, int32_t *bmGs, * * \retval ptr to start of the match; NULL if no match */ -uint8_t *BoyerMooreNocase(uint8_t *x, int32_t m, uint8_t *y, int32_t n, int32_t *bmGs, int32_t *bmBc) { +uint8_t *BoyerMooreNocase(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, uint16_t *bmGs, uint16_t *bmBc) { int i, j, m1, m2; #if 0 printf("\nBad:\n"); diff --git a/src/util-spm-bm.h b/src/util-spm-bm.h index 47baf000cc..f854d5fe00 100644 --- a/src/util-spm-bm.h +++ b/src/util-spm-bm.h @@ -32,22 +32,23 @@ /* Context for booyer moore */ typedef struct BmCtx_ { - int32_t bmBc[ALPHABET_SIZE]; - int32_t *bmGs; // = SCMalloc(sizeof(int32_t)*(needlelen + 1)); + uint16_t bmBc[ALPHABET_SIZE]; + uint16_t *bmGs; // = SCMalloc(sizeof(int32_t)*(needlelen + 1)); } BmCtx; /** Prepare and return a Boyer Moore context */ -BmCtx *BoyerMooreCtxInit(uint8_t *needle, uint32_t needle_len); - -void BoyerMooreCtxToNocase(BmCtx *, uint8_t *, uint32_t); -void PreBmBc(const uint8_t *x, int32_t m, int32_t *bmBc); -void BoyerMooreSuffixes(const uint8_t *x, int32_t m, int32_t *suff); -int PreBmGs(const uint8_t *, int32_t, int32_t *); -uint8_t *BoyerMoore(uint8_t *x, int32_t m, uint8_t *y, int32_t n, int32_t *bmGs, int32_t *bmBc); -void PreBmBcNocase(const uint8_t *x, int32_t m, int32_t *bmBc); -void BoyerMooreSuffixesNocase(const uint8_t *x, int32_t m, int32_t *suff); -void PreBmGsNocase(const uint8_t *x, int32_t m, int32_t *bmGs); -uint8_t *BoyerMooreNocase(uint8_t *x, int32_t m, uint8_t *y, int32_t n, int32_t *bmGs, int32_t *bmBc); +BmCtx *BoyerMooreCtxInit(uint8_t *needle, uint16_t needle_len); + +void BoyerMooreCtxToNocase(BmCtx *, uint8_t *, uint16_t); +void PreBmBc(const uint8_t *x, uint16_t m, uint16_t *bmBc); +void BoyerMooreSuffixes(const uint8_t *x, uint16_t m, uint16_t *suff); +int PreBmGs(const uint8_t *, uint16_t, uint16_t *); +uint8_t *BoyerMoore(uint8_t *x, int16_t m, uint8_t *y, int32_t n, uint16_t *bmGs, uint16_t *bmBc); +void PreBmBcNocase(const uint8_t *x, uint16_t m, uint16_t *bmBc); +void BoyerMooreSuffixesNocase(const uint8_t *x, uint16_t m, uint16_t *suff); +void PreBmGsNocase(const uint8_t *x, uint16_t m, uint16_t *bmGs); +uint8_t *BoyerMooreNocase(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, uint16_t *bmGs, uint16_t *bmBc); void BoyerMooreCtxDeInit(BmCtx *); + #endif /* __UTIL_SPM_BM__ */ diff --git a/src/util-spm-bs.c b/src/util-spm-bs.c index 4c7556a769..03ea7768eb 100644 --- a/src/util-spm-bs.c +++ b/src/util-spm-bs.c @@ -45,7 +45,7 @@ * * \retval ptr to start of the match; NULL if no match */ -uint8_t *BasicSearch(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *needle, uint32_t needle_len) { +uint8_t *BasicSearch(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *needle, uint16_t needle_len) { SCEnter(); const uint8_t *h, *n; @@ -98,7 +98,7 @@ uint8_t *BasicSearch(const uint8_t *haystack, uint32_t haystack_len, const uint8 * * \retval ptr to start of the match; NULL if no match */ -uint8_t *BasicSearchNocase(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *needle, uint32_t needle_len) { +uint8_t *BasicSearchNocase(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *needle, uint16_t needle_len) { const uint8_t *h, *n; const uint8_t *hmax = haystack + haystack_len; const uint8_t *nmax = needle + needle_len; diff --git a/src/util-spm-bs.h b/src/util-spm-bs.h index 6120b2c5f6..1e97f0baa0 100644 --- a/src/util-spm-bs.h +++ b/src/util-spm-bs.h @@ -28,8 +28,8 @@ #include "suricata-common.h" #include "suricata.h" -uint8_t *BasicSearch(const uint8_t *, uint32_t, const uint8_t *, uint32_t); -uint8_t *BasicSearchNocase(const uint8_t *, uint32_t, const uint8_t *, uint32_t); +uint8_t *BasicSearch(const uint8_t *, uint32_t, const uint8_t *, uint16_t); +uint8_t *BasicSearchNocase(const uint8_t *, uint32_t, const uint8_t *, uint16_t); void BasicSearchInit (void); #endif /* __UTIL_SPM_BS__ */ diff --git a/src/util-spm-bs2bm.c b/src/util-spm-bs2bm.c index 01385d8dcc..4d26f44204 100644 --- a/src/util-spm-bs2bm.c +++ b/src/util-spm-bs2bm.c @@ -40,7 +40,7 @@ * characters that can't be inside the needle_len. So the skips can be * faster */ -void Bs2BmBadchars(const uint8_t *needle, uint32_t needle_len, uint8_t *badchars) { +void Bs2BmBadchars(const uint8_t *needle, uint16_t needle_len, uint8_t *badchars) { uint32_t i; for (i = 0; i < ALPHABET_SIZE; i++) badchars[i] = 1; @@ -61,7 +61,7 @@ void Bs2BmBadchars(const uint8_t *needle, uint32_t needle_len, uint8_t *badchars * characters that can't be inside the needle_len. So the skips can be * faster */ -void Bs2BmBadcharsNocase(const uint8_t *needle, uint32_t needle_len, uint8_t *badchars) { +void Bs2BmBadcharsNocase(const uint8_t *needle, uint16_t needle_len, uint8_t *badchars) { uint32_t i; for (i = 0; i < ALPHABET_SIZE; i++) badchars[i] = 1; @@ -88,7 +88,7 @@ void Bs2BmBadcharsNocase(const uint8_t *needle, uint32_t needle_len, uint8_t *ba * * \retval ptr to start of the match; NULL if no match */ -uint8_t * Bs2Bm(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *needle, uint32_t needle_len, uint8_t badchars[]) +uint8_t * Bs2Bm(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *needle, uint16_t needle_len, uint8_t badchars[]) { const uint8_t *h, *n; const uint8_t *hmax = haystack + haystack_len; @@ -137,7 +137,7 @@ uint8_t * Bs2Bm(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *n * * \retval ptr to start of the match; NULL if no match */ -uint8_t *Bs2BmNocase(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *needle, uint32_t needle_len, uint8_t badchars[]) +uint8_t *Bs2BmNocase(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *needle, uint16_t needle_len, uint8_t badchars[]) { const uint8_t *h, *n; const uint8_t *hmax = haystack + haystack_len; diff --git a/src/util-spm-bs2bm.h b/src/util-spm-bs2bm.h index 7a47ddd3cf..a71b1282b8 100644 --- a/src/util-spm-bs2bm.h +++ b/src/util-spm-bs2bm.h @@ -29,10 +29,10 @@ #define ALPHABET_SIZE 256 -void Bs2BmBadchars(const uint8_t *, uint32_t, uint8_t *); -void Bs2BmBadcharsNocase(const uint8_t *, uint32_t, uint8_t *); -uint8_t * Bs2Bm(const uint8_t *, uint32_t, const uint8_t *, uint32_t, uint8_t []); -uint8_t *Bs2BmNocase(const uint8_t *, uint32_t, const uint8_t *, uint32_t, uint8_t []); +void Bs2BmBadchars(const uint8_t *, uint16_t, uint8_t *); +void Bs2BmBadcharsNocase(const uint8_t *, uint16_t, uint8_t *); +uint8_t * Bs2Bm(const uint8_t *, uint32_t, const uint8_t *, uint16_t, uint8_t []); +uint8_t *Bs2BmNocase(const uint8_t *, uint32_t, const uint8_t *, uint16_t, uint8_t []); #endif /* __UTIL_SPM_BS2BM__ */ diff --git a/src/util-spm.c b/src/util-spm.c index 68c8d3431a..d83fc37780 100644 --- a/src/util-spm.c +++ b/src/util-spm.c @@ -68,7 +68,7 @@ * \param needle pattern to search for * \param needlelen length of the pattern */ -uint8_t *Bs2bmSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint32_t needlelen) { +uint8_t *Bs2bmSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen) { uint8_t badchars[ALPHABET_SIZE]; Bs2BmBadchars(needle, needlelen, badchars); @@ -83,7 +83,7 @@ uint8_t *Bs2bmSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint32_t * \param needle pattern to search for * \param needlelen length of the pattern */ -uint8_t *Bs2bmNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint32_t needlelen) { +uint8_t *Bs2bmNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen) { uint8_t badchars[ALPHABET_SIZE]; Bs2BmBadchars(needle, needlelen, badchars); @@ -99,9 +99,9 @@ uint8_t *Bs2bmNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uin * \param needle pattern to search for * \param needlelen length of the pattern */ -uint8_t *BoyerMooreSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint32_t needlelen) { - int32_t bmBc[ALPHABET_SIZE]; - int32_t *bmGs = SCMalloc(sizeof(int32_t)*(needlelen + 1)); +uint8_t *BoyerMooreSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen) { + uint16_t bmBc[ALPHABET_SIZE]; + uint16_t *bmGs = SCMalloc(sizeof(uint16_t)*(needlelen + 1)); if (bmGs == NULL) return NULL; @@ -123,9 +123,9 @@ uint8_t *BoyerMooreSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint * \param needle pattern to search for * \param needlelen length of the pattern */ -uint8_t *BoyerMooreNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint32_t needlelen) { - int32_t bmBc[ALPHABET_SIZE]; - int32_t *bmGs = SCMalloc(sizeof(int32_t)*(needlelen + 1)); +uint8_t *BoyerMooreNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen) { + uint16_t bmBc[ALPHABET_SIZE]; + uint16_t *bmGs = SCMalloc(sizeof(uint16_t)*(needlelen + 1)); if (bmGs == NULL) return NULL; @@ -157,7 +157,7 @@ uint8_t *BoyerMooreNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle */ uint8_t *BasicSearchWrapper(uint8_t *text, uint8_t *needle, int times) { uint32_t textlen = strlen((char *)text); - uint32_t needlelen = strlen((char *)needle); + uint16_t needlelen = strlen((char *)needle); uint8_t *ret = NULL; int i = 0; @@ -176,7 +176,7 @@ uint8_t *BasicSearchWrapper(uint8_t *text, uint8_t *needle, int times) { uint8_t *BasicSearchNocaseWrapper(uint8_t *text, uint8_t *needle, int times) { uint32_t textlen = strlen((char *)text); - uint32_t needlelen = strlen((char *)needle); + uint16_t needlelen = strlen((char *)needle); uint8_t *ret = NULL; int i = 0; @@ -192,7 +192,7 @@ uint8_t *BasicSearchNocaseWrapper(uint8_t *text, uint8_t *needle, int times) { uint8_t *Bs2bmWrapper(uint8_t *text, uint8_t *needle, int times) { uint32_t textlen = strlen((char *)text); - uint32_t needlelen = strlen((char *)needle); + uint16_t needlelen = strlen((char *)needle); uint8_t badchars[ALPHABET_SIZE]; Bs2BmBadchars(needle, needlelen, badchars); @@ -211,7 +211,7 @@ uint8_t *Bs2bmWrapper(uint8_t *text, uint8_t *needle, int times) { uint8_t *Bs2bmNocaseWrapper(uint8_t *text, uint8_t *needle, int times) { uint32_t textlen = strlen((char *)text); - uint32_t needlelen = strlen((char *)needle); + uint16_t needlelen = strlen((char *)needle); uint8_t badchars[ALPHABET_SIZE]; Bs2BmBadchars(needle, needlelen, badchars); @@ -230,10 +230,10 @@ uint8_t *Bs2bmNocaseWrapper(uint8_t *text, uint8_t *needle, int times) { uint8_t *BoyerMooreWrapper(uint8_t *text, uint8_t *needle, int times) { uint32_t textlen = strlen((char *)text); - uint32_t needlelen = strlen((char *)needle); + uint16_t needlelen = strlen((char *)needle); - int32_t bmBc[ALPHABET_SIZE]; - int32_t *bmGs = SCMalloc(sizeof(int32_t)*(needlelen + 1)); + uint16_t bmBc[ALPHABET_SIZE]; + uint16_t *bmGs = SCMalloc(sizeof(uint16_t)*(needlelen + 1)); if (bmGs == NULL) return NULL; @@ -255,10 +255,10 @@ uint8_t *BoyerMooreWrapper(uint8_t *text, uint8_t *needle, int times) { uint8_t *BoyerMooreNocaseWrapper(uint8_t *text, uint8_t *needle, int times) { uint32_t textlen = strlen((char *)text); - uint32_t needlelen = strlen((char *)needle); + uint16_t needlelen = strlen((char *)needle); - int32_t bmBc[ALPHABET_SIZE]; - int32_t *bmGs = SCMalloc(sizeof(int32_t)*(needlelen + 1)); + uint16_t bmBc[ALPHABET_SIZE]; + uint16_t *bmGs = SCMalloc(sizeof(uint16_t)*(needlelen + 1)); if (bmGs == NULL) return NULL; @@ -288,7 +288,7 @@ uint8_t *BoyerMooreNocaseWrapper(uint8_t *text, uint8_t *needle, int times) { */ uint8_t *BasicSearchCtxWrapper(uint8_t *text, uint8_t *needle, int times) { uint32_t textlen = strlen((char *)text); - uint32_t needlelen = strlen((char *)needle); + uint16_t needlelen = strlen((char *)needle); uint8_t *ret = NULL; int i = 0; @@ -305,7 +305,7 @@ uint8_t *BasicSearchCtxWrapper(uint8_t *text, uint8_t *needle, int times) { uint8_t *BasicSearchNocaseCtxWrapper(uint8_t *text, uint8_t *needle, int times) { uint32_t textlen = strlen((char *)text); - uint32_t needlelen = strlen((char *)needle); + uint16_t needlelen = strlen((char *)needle); uint8_t *ret = NULL; int i = 0; @@ -322,7 +322,7 @@ uint8_t *BasicSearchNocaseCtxWrapper(uint8_t *text, uint8_t *needle, int times) uint8_t *Bs2bmCtxWrapper(uint8_t *text, uint8_t *needle, int times) { uint32_t textlen = strlen((char *)text); - uint32_t needlelen = strlen((char *)needle); + uint16_t needlelen = strlen((char *)needle); uint8_t badchars[ALPHABET_SIZE]; @@ -342,7 +342,7 @@ uint8_t *Bs2bmCtxWrapper(uint8_t *text, uint8_t *needle, int times) { uint8_t *Bs2bmNocaseCtxWrapper(uint8_t *text, uint8_t *needle, int times) { uint32_t textlen = strlen((char *)text); - uint32_t needlelen = strlen((char *)needle); + uint16_t needlelen = strlen((char *)needle); uint8_t badchars[ALPHABET_SIZE]; @@ -362,10 +362,10 @@ uint8_t *Bs2bmNocaseCtxWrapper(uint8_t *text, uint8_t *needle, int times) { uint8_t *BoyerMooreCtxWrapper(uint8_t *text, uint8_t *needle, int times) { uint32_t textlen = strlen((char *)text); - uint32_t needlelen = strlen((char *)needle); + uint16_t needlelen = strlen((char *)needle); - int32_t bmBc[ALPHABET_SIZE]; - int32_t *bmGs = SCMalloc(sizeof(int32_t)*(needlelen + 1)); + uint16_t bmBc[ALPHABET_SIZE]; + uint16_t *bmGs = SCMalloc(sizeof(uint16_t)*(needlelen + 1)); if (bmGs == NULL) return NULL; @@ -388,7 +388,7 @@ uint8_t *BoyerMooreCtxWrapper(uint8_t *text, uint8_t *needle, int times) { uint8_t *RawCtxWrapper(uint8_t *text, uint8_t *needle, int times) { uint32_t textlen = strlen((char *)text); - uint32_t needlelen = strlen((char *)needle); + uint16_t needlelen = strlen((char *)needle); uint8_t *ret = NULL; int i = 0; @@ -404,10 +404,10 @@ uint8_t *RawCtxWrapper(uint8_t *text, uint8_t *needle, int times) { uint8_t *BoyerMooreNocaseCtxWrapper(uint8_t *text, uint8_t *needle, int times) { uint32_t textlen = strlen((char *)text); - uint32_t needlelen = strlen((char *)needle); + uint16_t needlelen = strlen((char *)needle); - int32_t bmBc[ALPHABET_SIZE]; - int32_t *bmGs = SCMalloc(sizeof(int32_t)*(needlelen + 1)); + uint16_t bmBc[ALPHABET_SIZE]; + uint16_t *bmGs = SCMalloc(sizeof(uint16_t)*(needlelen + 1)); if (bmGs == NULL) return NULL; diff --git a/src/util-spm.h b/src/util-spm.h index 9d80d736d5..2dea657ee6 100644 --- a/src/util-spm.h +++ b/src/util-spm.h @@ -29,10 +29,10 @@ #include "util-spm-bm.h" /** Default algorithm to use: Boyer Moore */ -uint8_t *Bs2bmSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint32_t needlelen); -uint8_t *Bs2bmNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint32_t needlelen); -uint8_t *BoyerMooreSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint32_t needlelen); -uint8_t *BoyerMooreNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint32_t needlelen); +uint8_t *Bs2bmSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen); +uint8_t *Bs2bmNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen); +uint8_t *BoyerMooreSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen); +uint8_t *BoyerMooreNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen); /* Macros for automatic algorithm selection (use them only when you can't store the context) */ #define SpmSearch(text, textlen, needle, needlelen) ({\