]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
spm: constify search args
authorVictor Julien <victor@inliniac.net>
Fri, 13 Nov 2015 06:55:44 +0000 (07:55 +0100)
committerVictor Julien <victor@inliniac.net>
Wed, 2 Mar 2016 09:00:48 +0000 (10:00 +0100)
src/util-memcpy.h
src/util-spm-bm.c
src/util-spm-bm.h
src/util-spm.c
src/util-spm.h

index bdb80242b726e68ed94e411215f89714e34babf5..c2b8cd7997fc7bca3aa3c3793fe1f107b3e7128e 100644 (file)
@@ -35,7 +35,7 @@
  * \param s   Pointer to the src string for memcpy.
  * \param len len of the string sent in s.
  */
-static inline void memcpy_tolower(uint8_t *d, uint8_t *s, uint16_t len)
+static inline void memcpy_tolower(uint8_t *d, const uint8_t *s, uint16_t len)
 {
     uint16_t i;
     for (i = 0; i < len; i++)
index 7c5b8d2d4d656e2198df2394d80d5dbf9b92ac1d..dd16bb99dd473b3c65265f2a3f5d212584b4c676 100644 (file)
@@ -73,7 +73,7 @@ void BoyerMooreCtxToNocase(BmCtx *bm_ctx, uint8_t *needle, uint16_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, uint16_t needle_len)
+BmCtx *BoyerMooreCtxInit(const uint8_t *needle, uint16_t needle_len)
 {
     BmCtx *new = SCMalloc(sizeof(BmCtx));
     if (unlikely(new == NULL)) {
@@ -302,7 +302,7 @@ static void PreBmGsNocase(const uint8_t *x, uint16_t m, uint16_t *bmGs)
  *
  * \retval ptr to start of the match; NULL if no match
  */
-uint8_t *BoyerMoore(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, BmCtx *bm_ctx)
+uint8_t *BoyerMoore(const uint8_t *x, uint16_t m, const uint8_t *y, int32_t n, BmCtx *bm_ctx)
 {
     uint16_t *bmGs = bm_ctx->bmGs;
     uint16_t *bmBc = bm_ctx->bmBc;
@@ -324,7 +324,7 @@ uint8_t *BoyerMoore(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, BmCtx *bm_ctx
       for (i = m - 1; i >= 0 && x[i] == y[i + j]; --i);
 
       if (i < 0) {
-         return y + j;
+         return (uint8_t *)(y + j);
          //j += bmGs[0];
       } else {
  //        printf("%c", y[i+j]);
@@ -351,7 +351,7 @@ uint8_t *BoyerMoore(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, BmCtx *bm_ctx
  *
  * \retval ptr to start of the match; NULL if no match
  */
-uint8_t *BoyerMooreNocase(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, BmCtx *bm_ctx)
+uint8_t *BoyerMooreNocase(const uint8_t *x, uint16_t m, const uint8_t *y, int32_t n, BmCtx *bm_ctx)
 {
     uint16_t *bmGs = bm_ctx->bmGs;
     uint16_t *bmBc = bm_ctx->bmBc;
@@ -372,7 +372,7 @@ uint8_t *BoyerMooreNocase(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, BmCtx *
         for (i = m - 1; i >= 0 && x[i] == u8_tolower(y[i + j]); --i);
 
         if (i < 0) {
-            return y + j;
+            return (uint8_t *)(y + j);
         } else {
             j += (m1=bmGs[i]) > (m2=bmBc[u8_tolower(y[i + j])] - m + 1 + i)?m1:m2;
         }
index b3b97ced4bf56ab359b9734436ebc467a1391de2..051a10243b75deb63cc3c2a4a381d47f02782473 100644 (file)
@@ -37,12 +37,12 @@ typedef struct BmCtx_ {
 } BmCtx;
 
 /** Prepare and return a Boyer Moore context */
-BmCtx *BoyerMooreCtxInit(uint8_t *needle, uint16_t needle_len);
+BmCtx *BoyerMooreCtxInit(const uint8_t *needle, uint16_t needle_len);
 BmCtx *BoyerMooreNocaseCtxInit(uint8_t *needle, uint16_t needle_len);
 
 void BoyerMooreCtxToNocase(BmCtx *, uint8_t *, uint16_t);
-uint8_t *BoyerMoore(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, BmCtx *bm_ctx);
-uint8_t *BoyerMooreNocase(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, BmCtx *bm_ctx);
+uint8_t *BoyerMoore(const uint8_t *x, uint16_t m, const uint8_t *y, int32_t n, BmCtx *bm_ctx);
+uint8_t *BoyerMooreNocase(const uint8_t *x, uint16_t m, const uint8_t *y, int32_t n, BmCtx *bm_ctx);
 void BoyerMooreCtxDeInit(BmCtx *);
 
 #endif /* __UTIL_SPM_BM__ */
index 2da12e77889e2185137dd7f6d80c5c6e29d97b59..845795b8d8b37655960061d07197955615854926 100644 (file)
@@ -68,7 +68,8 @@
  * \param needle pattern to search for
  * \param needlelen length of the pattern
  */
-uint8_t *Bs2bmSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen)
+uint8_t *Bs2bmSearch(const uint8_t *text, uint32_t textlen,
+        const uint8_t *needle, uint16_t needlelen)
 {
     uint8_t badchars[ALPHABET_SIZE];
     Bs2BmBadchars(needle, needlelen, badchars);
@@ -84,7 +85,8 @@ uint8_t *Bs2bmSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_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, uint16_t needlelen)
+uint8_t *Bs2bmNocaseSearch(const uint8_t *text, uint32_t textlen,
+        const uint8_t *needle, uint16_t needlelen)
 {
     uint8_t badchars[ALPHABET_SIZE];
     Bs2BmBadchars(needle, needlelen, badchars);
@@ -101,7 +103,8 @@ 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, uint16_t needlelen)
+uint8_t *BoyerMooreSearch(const uint8_t *text, uint32_t textlen,
+        const uint8_t *needle, uint16_t needlelen)
 {
     BmCtx *bm_ctx = BoyerMooreCtxInit(needle, needlelen);
 
@@ -120,7 +123,8 @@ 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, uint16_t needlelen)
+uint8_t *BoyerMooreNocaseSearch(const uint8_t *text, uint32_t textlen,
+        uint8_t *needle, uint16_t needlelen)
 {
     BmCtx *bm_ctx = BoyerMooreNocaseCtxInit(needle, needlelen);
 
index 2dea657ee607962c07b66b65c186bc4add48ff82..bd1826923143a255ca89d757de134379998b147c 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, 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);
+uint8_t *Bs2bmSearch(const uint8_t *text, uint32_t textlen, const uint8_t *needle, uint16_t needlelen);
+uint8_t *Bs2bmNocaseSearch(const uint8_t *text, uint32_t textlen, const uint8_t *needle, uint16_t needlelen);
+uint8_t *BoyerMooreSearch(const uint8_t *text, uint32_t textlen, const uint8_t *needle, uint16_t needlelen);
+uint8_t *BoyerMooreNocaseSearch(const 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) ({\