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'
This commit is contained in:
Eli Fidler 2016-05-31 12:45:52 -04:00
parent 9dcf51c3a1
commit 05f0592b34

View File

@ -154,7 +154,11 @@ struct UTF8 {
}
unsigned char type = GetRange(static_cast<unsigned char>(c));
*codepoint = (0xFF >> type) & static_cast<unsigned char>(c);
if (type >= 32) {
*codepoint = 0;
} else {
*codepoint = (0xFF >> type) & static_cast<unsigned char>(c);
}
bool result = true;
switch (type) {
case 2: TAIL(); return result;