[Pcre-svn] [1762] code/trunk: Tidies to get rid of sanitize …

Page principale
Supprimer ce message
Auteur: Subversion repository
Date:  
À: pcre-svn
Sujet: [Pcre-svn] [1762] code/trunk: Tidies to get rid of sanitize warnings ( mostly about left shifts).
Revision: 1762
          http://vcs.pcre.org/viewvc?view=rev&revision=1762
Author:   ph10
Date:     2020-02-11 18:13:46 +0000 (Tue, 11 Feb 2020)
Log Message:
-----------
Tidies to get rid of sanitize warnings (mostly about left shifts).


Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/pcre_compile.c
    code/trunk/pcre_jit_compile.c
    code/trunk/pcretest.c
    code/trunk/testdata/testinput2
    code/trunk/testdata/testoutput2


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2020-02-10 17:17:34 UTC (rev 1761)
+++ code/trunk/ChangeLog    2020-02-11 18:13:46 UTC (rev 1762)
@@ -30,7 +30,10 @@
 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
-----------------------------


Modified: code/trunk/pcre_compile.c
===================================================================
--- code/trunk/pcre_compile.c    2020-02-10 17:17:34 UTC (rev 1761)
+++ code/trunk/pcre_compile.c    2020-02-11 18:13:46 UTC (rev 1762)
@@ -68,7 +68,7 @@


/* 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 @@

/* 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 @@
       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 @@
               {
               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 @@
         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 @@
             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 @@
             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;
      }



Modified: code/trunk/pcre_jit_compile.c
===================================================================
--- code/trunk/pcre_jit_compile.c    2020-02-10 17:17:34 UTC (rev 1761)
+++ code/trunk/pcre_jit_compile.c    2020-02-11 18:13:46 UTC (rev 1762)
@@ -3938,10 +3938,10 @@
 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 @@
   /* 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;
 }


Modified: code/trunk/pcretest.c
===================================================================
--- code/trunk/pcretest.c    2020-02-10 17:17:34 UTC (rev 1761)
+++ code/trunk/pcretest.c    2020-02-11 18:13:46 UTC (rev 1762)
@@ -500,7 +500,7 @@
 #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 @@

           /* 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 @@
         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 @@
         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 @@


         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 @@


         for (i = 0; i < 32; i++)
           {
-          if ((getstrings & (1 << i)) != 0)
+          if ((getstrings & (1U << i)) != 0)
             {
             int rc;
             const char *substring;


Modified: code/trunk/testdata/testinput2
===================================================================
--- code/trunk/testdata/testinput2    2020-02-10 17:17:34 UTC (rev 1761)
+++ code/trunk/testdata/testinput2    2020-02-11 18:13:46 UTC (rev 1762)
@@ -1380,7 +1380,7 @@
     1X
     123456\P


-//KF>testsavedregex
+//S-KF>testsavedregex

/abc/IS>testsavedregex
<testsavedregex

Modified: code/trunk/testdata/testoutput2
===================================================================
--- code/trunk/testdata/testoutput2    2020-02-10 17:17:34 UTC (rev 1761)
+++ code/trunk/testdata/testoutput2    2020-02-11 18:13:46 UTC (rev 1762)
@@ -5614,9 +5614,8 @@
     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