]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
update all spm algos to use 16 bit pattern lengths. Should compress a lot of tables
authorAnoop Saldanha <poonaatsoc@gmail.com>
Thu, 22 Mar 2012 11:45:15 +0000 (17:15 +0530)
committerVictor Julien <victor@inliniac.net>
Thu, 22 Mar 2012 14:58:02 +0000 (15:58 +0100)
src/suricata.c
src/util-spm-bm.c
src/util-spm-bm.h
src/util-spm-bs.c
src/util-spm-bs.h
src/util-spm-bs2bm.c
src/util-spm-bs2bm.h
src/util-spm.c
src/util-spm.h

index 9459f376a5b200cc07ab7553c1990eaa5de1ba27..794259ce5d31daa12e28c82462ab598ce991818d 100644 (file)
 #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.
index e4c3bffeea2a249d10c52f5604a6a3764051065c..b4aa11d2cd16834561ff96f9c3d2648576c1aa04 100644 (file)
@@ -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");
index 47baf000cc281fe78309966723f6a8310137e016..f854d5fe00872ba716bc7899d46bf918ceb79dae 100644 (file)
 
 /* 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__ */
 
index 4c7556a7695f60404ca89173a89bdac5fc9f8626..03ea7768eb3cb2e78da0fb71e37c7295ef850206 100644 (file)
@@ -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;
index 6120b2c5f608c3fa89e4d792b01c8372c8c3a9f6..1e97f0baa07c96d615e06c4633a01177b28bb700 100644 (file)
@@ -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__ */
index 01385d8dccbc303fb9a751d32ed14677b2cee793..4d26f442042d228efc7f3dd629d1e63279721367 100644 (file)
@@ -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;
index 7a47ddd3cfb995cf7ae06c4ea6ea0ed04c49ce30..a71b1282b88637fd3d3e6710439daa60ee571c38 100644 (file)
 
 #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__ */
 
index 68c8d3431a88a805aaf596d57aafabe8b5d8b65e..d83fc37780ac80f257285369c23d5de977a176ae 100644 (file)
@@ -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;
 
index 9d80d736d5781a84b0f067c5fce77abff29823ad..2dea657ee607962c07b66b65c186bc4add48ff82 100644 (file)
 #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) ({\