From 05f0592b34cb943e7c96b8767d716431a3d9eaef Mon Sep 17 00:00:00 2001 From: Eli Fidler Date: Tue, 31 May 2016 12:45:52 -0400 Subject: [PATCH] avoid shift out-of-range error UBSAN gave in Regex.Unicode test: include/rapidjson/encodings.h:157:28: runtime error: shift exponent 32 is too large for 32-bit type 'int' --- include/rapidjson/encodings.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/rapidjson/encodings.h b/include/rapidjson/encodings.h index edfc990..baa7c2b 100644 --- a/include/rapidjson/encodings.h +++ b/include/rapidjson/encodings.h @@ -154,7 +154,11 @@ struct UTF8 { } unsigned char type = GetRange(static_cast(c)); - *codepoint = (0xFF >> type) & static_cast(c); + if (type >= 32) { + *codepoint = 0; + } else { + *codepoint = (0xFF >> type) & static_cast(c); + } bool result = true; switch (type) { case 2: TAIL(); return result;