Fix sanitize=undefined warnings for left shifts of 31.
diff --git a/ChangeLog b/ChangeLog
index 4264b0a..a2e6af1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -123,6 +123,9 @@
current group, for example in this pattern: /(?|(\k'Pm')|(?'Pm'))/, caused a
buffer overflow at compile time. This bug was discovered by the LLVM fuzzer.
+31. Fix -fsanitize=undefined warnings for left shifts of 1 by 31 (it treats 1
+as an int; fixed by writing it as 1u).
+
Version 10.10 06-March-2015
---------------------------
diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c
index 41c6ae8..32c2aa2 100644
--- a/src/pcre2_compile.c
+++ b/src/pcre2_compile.c
@@ -6057,7 +6057,7 @@
{
open_capitem *oc;
recno = GET2(slot, 0);
- cb->backref_map |= (recno < 32)? (1 << recno) : 1;
+ cb->backref_map |= (recno < 32)? (1u << recno) : 1;
if ((uint32_t)recno > cb->top_backref) cb->top_backref = recno;
/* Check to see if this back reference is recursive, that is, it
@@ -6686,7 +6686,7 @@
item_hwm_offset = cb->hwm - cb->start_workspace;
*code++ = ((options & PCRE2_CASELESS) != 0)? OP_REFI : OP_REF;
PUT2INC(code, 0, recno);
- cb->backref_map |= (recno < 32)? (1 << recno) : 1;
+ cb->backref_map |= (recno < 32)? (1u << recno) : 1;
if ((uint32_t)recno > cb->top_backref) cb->top_backref = recno;
/* Check to see if this back reference is recursive, that it, it
@@ -7302,7 +7302,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, cb, atomcount)) return FALSE;
}
@@ -7426,7 +7426,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, cb, atomcount)) return FALSE;
}