[Pcre-svn] [1085] code/trunk/src: Casts and rewrites to avoi…

Page principale
Supprimer ce message
Auteur: Subversion repository
Date:  
À: pcre-svn
Sujet: [Pcre-svn] [1085] code/trunk/src: Casts and rewrites to avoid clang sanitize warnings.
Revision: 1085
          http://www.exim.org/viewvc/pcre2?view=rev&revision=1085
Author:   ph10
Date:     2019-04-16 15:49:07 +0100 (Tue, 16 Apr 2019)
Log Message:
-----------
Casts and rewrites to avoid clang sanitize warnings.


Modified Paths:
--------------
    code/trunk/src/pcre2_compile.c
    code/trunk/src/pcre2_printint.c
    code/trunk/src/pcre2test.c


Modified: code/trunk/src/pcre2_compile.c
===================================================================
--- code/trunk/src/pcre2_compile.c    2019-04-16 08:57:10 UTC (rev 1084)
+++ code/trunk/src/pcre2_compile.c    2019-04-16 14:49:07 UTC (rev 1085)
@@ -5948,7 +5948,10 @@
         (void)memmove(code + (32 / sizeof(PCRE2_UCHAR)), code,
           CU2BYTES(class_uchardata - code));
         if (negate_class && !xclass_has_prop)
-          for (i = 0; i < 32; i++) classbits[i] = ~classbits[i];
+          { 
+          /* Using 255 ^ instead of ~ avoids clang sanitize warning. */ 
+          for (i = 0; i < 32; i++) classbits[i] = 255 ^ classbits[i];
+          } 
         memcpy(code, classbits, 32);
         code = class_uchardata + (32 / sizeof(PCRE2_UCHAR));
         }
@@ -5971,7 +5974,10 @@
     if (lengthptr == NULL)    /* Save time in the pre-compile phase */
       {
       if (negate_class)
-        for (i = 0; i < 32; i++) classbits[i] = ~classbits[i];
+        { 
+       /* Using 255 ^ instead of ~ avoids clang sanitize warning. */ 
+       for (i = 0; i < 32; i++) classbits[i] = 255 ^ classbits[i];
+       } 
       memcpy(code, classbits, 32);
       }
     code += 32 / sizeof(PCRE2_UCHAR);


Modified: code/trunk/src/pcre2_printint.c
===================================================================
--- code/trunk/src/pcre2_printint.c    2019-04-16 08:57:10 UTC (rev 1084)
+++ code/trunk/src/pcre2_printint.c    2019-04-16 14:49:07 UTC (rev 1085)
@@ -673,7 +673,8 @@
         map = (uint8_t *)ccode;
         if (invertmap)
           {
-          for (i = 0; i < 32; i++) inverted_map[i] = ~map[i];
+          /* Using 255 ^ instead of ~ avoids clang sanitize warning. */ 
+          for (i = 0; i < 32; i++) inverted_map[i] = 255 ^ map[i];
           map = inverted_map;
           }



Modified: code/trunk/src/pcre2test.c
===================================================================
--- code/trunk/src/pcre2test.c    2019-04-16 08:57:10 UTC (rev 1084)
+++ code/trunk/src/pcre2test.c    2019-04-16 14:49:07 UTC (rev 1085)
@@ -6861,7 +6861,7 @@
         fprintf(outfile, "** Truncation will probably give the wrong "
           "result.\n");
         }
-      *q8++ = c;
+      *q8++ = (uint8_t)c;
       }
     }
 #endif
@@ -6895,7 +6895,7 @@
           "result.\n");
         }


-      *q16++ = c;
+      *q16++ = (uint16_t)c;
       }
     }
 #endif