From: Victor Julien Date: Fri, 13 Nov 2015 06:55:44 +0000 (+0100) Subject: spm: constify search args X-Git-Tag: suricata-3.0.1RC1~85 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e3514a4449f3c274f82aa08b5a4e0e5272fa55e;p=thirdparty%2Fsuricata.git spm: constify search args --- diff --git a/src/util-memcpy.h b/src/util-memcpy.h index bdb80242b7..c2b8cd7997 100644 --- a/src/util-memcpy.h +++ b/src/util-memcpy.h @@ -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++) diff --git a/src/util-spm-bm.c b/src/util-spm-bm.c index 7c5b8d2d4d..dd16bb99dd 100644 --- a/src/util-spm-bm.c +++ b/src/util-spm-bm.c @@ -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; } diff --git a/src/util-spm-bm.h b/src/util-spm-bm.h index b3b97ced4b..051a10243b 100644 --- a/src/util-spm-bm.h +++ b/src/util-spm-bm.h @@ -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__ */ diff --git a/src/util-spm.c b/src/util-spm.c index 2da12e7788..845795b8d8 100644 --- a/src/util-spm.c +++ b/src/util-spm.c @@ -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); diff --git a/src/util-spm.h b/src/util-spm.h index 2dea657ee6..bd18269231 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, 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) ({\