From 4acee004ecce1e5349f6b6ebbdc513b2863d799f Mon Sep 17 00:00:00 2001 From: "Philip.Hazel" Date: Tue, 16 Apr 2019 14:49:07 +0000 Subject: [PATCH] Casts and rewrites to avoid clang sanitize warnings. --- src/pcre2_compile.c | 10 ++++++++-- src/pcre2_printint.c | 3 ++- src/pcre2test.c | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c index 30db6d5..ab48d2d 100644 --- a/src/pcre2_compile.c +++ b/src/pcre2_compile.c @@ -5948,7 +5948,10 @@ for (;; pptr++) (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 @@ for (;; pptr++) 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); diff --git a/src/pcre2_printint.c b/src/pcre2_printint.c index a903826..36909ef 100644 --- a/src/pcre2_printint.c +++ b/src/pcre2_printint.c @@ -673,7 +673,8 @@ for(;;) 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; } diff --git a/src/pcre2test.c b/src/pcre2test.c index c9757e9..4010772 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c @@ -6861,7 +6861,7 @@ while ((c = *p++) != 0) fprintf(outfile, "** Truncation will probably give the wrong " "result.\n"); } - *q8++ = c; + *q8++ = (uint8_t)c; } } #endif @@ -6895,7 +6895,7 @@ while ((c = *p++) != 0) "result.\n"); } - *q16++ = c; + *q16++ = (uint16_t)c; } } #endif