diff options
author | ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15> | 2020-02-11 18:13:46 +0000 |
---|---|---|
committer | ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15> | 2020-02-11 18:13:46 +0000 |
commit | be73d3747c3b2c0dab935279484bf96d55221106 (patch) | |
tree | 515517e5caa6eaa5f1341091f05e6b82f9e5b804 | |
parent | 3a9026509f9c1745f378595e55e5024361ad152d (diff) | |
download | pcre-be73d3747c3b2c0dab935279484bf96d55221106.tar.gz |
Tidies to get rid of sanitize warnings (mostly about left shifts).
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@1762 2f5784b3-3f2a-0410-8824-cb99058d5e15
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | pcre_compile.c | 16 | ||||
-rw-r--r-- | pcre_jit_compile.c | 6 | ||||
-rw-r--r-- | pcretest.c | 12 | ||||
-rw-r--r-- | testdata/testinput2 | 2 | ||||
-rw-r--r-- | testdata/testoutput2 | 3 |
6 files changed, 22 insertions, 20 deletions
@@ -30,6 +30,9 @@ sanitizer complaint (regexec is supposed to be thread safe). 6. Check the size of the number after (?C as it is read, in order to avoid integer overflow. +7. Tidy up left shifts to avoid sanitize warnings; also fix one NULL deference +in pcretest. + Version 8.43 23-February-2019 ----------------------------- diff --git a/pcre_compile.c b/pcre_compile.c index 1e3d6c3..32e5b91 100644 --- a/pcre_compile.c +++ b/pcre_compile.c @@ -68,7 +68,7 @@ COMPILE_PCREx macro will already be appropriately set. */ /* Macro for setting individual bits in class bitmaps. */ -#define SETBIT(a,b) a[(b)/8] |= (1 << ((b)&7)) +#define SETBIT(a,b) a[(b)/8] |= (1U << ((b)&7)) /* Maximum length value to check against when making sure that the integer that holds the compiled pattern length does not overflow. We make it a bit less than @@ -129,8 +129,8 @@ overrun before it actually does run off the end of the data block. */ /* Private flags added to firstchar and reqchar. */ -#define REQ_CASELESS (1 << 0) /* Indicates caselessness */ -#define REQ_VARY (1 << 1) /* Reqchar followed non-literal item */ +#define REQ_CASELESS (1U << 0) /* Indicates caselessness */ +#define REQ_VARY (1U << 1) /* Reqchar followed non-literal item */ /* Negative values for the firstchar and reqchar flags */ #define REQ_UNSET (-2) #define REQ_NONE (-1) @@ -3611,7 +3611,7 @@ for(;;) if (chr > 255) break; class_bitset = (pcre_uint8 *) ((list_ptr == list ? code : base_end) - list_ptr[2]); - if ((class_bitset[chr >> 3] & (1 << (chr & 7))) != 0) return FALSE; + if ((class_bitset[chr >> 3] & (1U << (chr & 7))) != 0) return FALSE; break; #if defined SUPPORT_UTF || !defined COMPILE_PCRE8 @@ -7458,7 +7458,7 @@ for (;; ptr++) { open_capitem *oc; recno = GET2(slot, 0); - cd->backref_map |= (recno < 32)? (1 << recno) : 1; + cd->backref_map |= (recno < 32)? (1U << recno) : 1; if (recno > cd->top_backref) cd->top_backref = recno; /* Check to see if this back reference is recursive, that it, it @@ -8069,7 +8069,7 @@ for (;; ptr++) item_hwm_offset = cd->hwm - cd->start_workspace; *code++ = ((options & PCRE_CASELESS) != 0)? OP_REFI : OP_REF; PUT2INC(code, 0, recno); - cd->backref_map |= (recno < 32)? (1 << recno) : 1; + cd->backref_map |= (recno < 32)? (1U << recno) : 1; if (recno > cd->top_backref) cd->top_backref = recno; /* Check to see if this back reference is recursive, that it, it @@ -8682,7 +8682,7 @@ do { op == OP_SCBRA || op == OP_SCBRAPOS) { int n = GET2(scode, 1+LINK_SIZE); - int new_map = bracket_map | ((n < 32)? (1 << n) : 1); + int new_map = bracket_map | ((n < 32)? (1U << n) : 1); if (!is_anchored(scode, new_map, cd, atomcount)) return FALSE; } @@ -8810,7 +8810,7 @@ do { op == OP_SCBRA || op == OP_SCBRAPOS) { int n = GET2(scode, 1+LINK_SIZE); - int new_map = bracket_map | ((n < 32)? (1 << n) : 1); + int new_map = bracket_map | ((n < 32)? (1U << n) : 1); if (!is_startline(scode, new_map, cd, atomcount, inassert)) return FALSE; } diff --git a/pcre_jit_compile.c b/pcre_jit_compile.c index bc5f9c0..4dcf8fc 100644 --- a/pcre_jit_compile.c +++ b/pcre_jit_compile.c @@ -3938,10 +3938,10 @@ static sljit_s32 character_to_int32(pcre_uchar chr) sljit_s32 value = (sljit_s32)chr; #if defined COMPILE_PCRE8 #define SSE2_COMPARE_TYPE_INDEX 0 -return (value << 24) | (value << 16) | (value << 8) | value; +return ((unsigned int)value << 24) | ((unsigned int)value << 16) | ((unsigned int)value << 8) | (unsigned int)value; #elif defined COMPILE_PCRE16 #define SSE2_COMPARE_TYPE_INDEX 1 -return (value << 16) | value; +return ((unsigned int)value << 16) | value; #elif defined COMPILE_PCRE32 #define SSE2_COMPARE_TYPE_INDEX 2 return value; @@ -8507,7 +8507,7 @@ if (opcode == OP_ONCE) /* We temporarily encode the needs_control_head in the lowest bit. Note: on the target architectures of SLJIT the ((x << 1) >> 1) returns the same value for small signed numbers (including negative numbers). */ - BACKTRACK_AS(bracket_backtrack)->u.framesize = (BACKTRACK_AS(bracket_backtrack)->u.framesize << 1) | (needs_control_head ? 1 : 0); + BACKTRACK_AS(bracket_backtrack)->u.framesize = ((unsigned int)BACKTRACK_AS(bracket_backtrack)->u.framesize << 1) | (needs_control_head ? 1 : 0); } return cc + repeat_length; } @@ -500,7 +500,7 @@ enum { #if (defined (SUPPORT_PCRE8) + defined (SUPPORT_PCRE16) + \ defined (SUPPORT_PCRE32)) >= 2 -#define CHAR_SIZE (1 << pcre_mode) +#define CHAR_SIZE (1U << pcre_mode) /* There doesn't seem to be an easy way of writing these macros that can cope with the 3 pairs of bit sizes plus all three bit sizes. So just handle all the @@ -4443,7 +4443,7 @@ while (!done) /* If there is study data, write it. */ - if (extra != NULL) + if (extra != NULL && (extra->flags & PCRE_EXTRA_STUDY_DATA) != 0) { if (fwrite(extra->study_data, 1, true_study_size, f) < true_study_size) @@ -4735,7 +4735,7 @@ while (!done) if (isdigit(*p)) /* Set copy string */ { while(isdigit(*p)) n = n * 10 + *p++ - '0'; - copystrings |= 1 << n; + copystrings |= 1U << n; } else if (isalnum(*p)) { @@ -4798,7 +4798,7 @@ while (!done) if (isdigit(*p)) { while(isdigit(*p)) n = n * 10 + *p++ - '0'; - getstrings |= 1 << n; + getstrings |= 1U << n; } else if (isalnum(*p)) { @@ -5335,7 +5335,7 @@ while (!done) for (i = 0; i < 32; i++) { - if ((copystrings & (1 << i)) != 0) + if ((copystrings & (1U << i)) != 0) { int rc; char copybuffer[256]; @@ -5400,7 +5400,7 @@ while (!done) for (i = 0; i < 32; i++) { - if ((getstrings & (1 << i)) != 0) + if ((getstrings & (1U << i)) != 0) { int rc; const char *substring; diff --git a/testdata/testinput2 b/testdata/testinput2 index 3528de1..53c9825 100644 --- a/testdata/testinput2 +++ b/testdata/testinput2 @@ -1380,7 +1380,7 @@ 1X 123456\P -//KF>testsavedregex +//S-KF>testsavedregex /abc/IS>testsavedregex <testsavedregex diff --git a/testdata/testoutput2 b/testdata/testoutput2 index 4ccda27..f5d32d6 100644 --- a/testdata/testoutput2 +++ b/testdata/testoutput2 @@ -5614,9 +5614,8 @@ No match 123456\P No match -//KF>testsavedregex +//S-KF>testsavedregex Compiled pattern written to testsavedregex -Study data written to testsavedregex /abc/IS>testsavedregex Capturing subpattern count = 0 |