Limit hexadecimal escape sequence length
Helps with cases like "\xFFecho" by limiting the number of hex digits that will be parsed to maximum suitable for the char type. This rule differs from the C/C++ standard, but ChaiScript does not offer the same workaround options. Furthermore, without it having hexadecimal sequences longer than can fit into the char type is undefined behavior anyway.
This commit is contained in:
parent
34c6b17215
commit
202204a82a
@ -981,6 +981,14 @@ namespace chaiscript
|
||||
|
||||
if (is_hex_char) {
|
||||
hex_matches.push_back(t_char);
|
||||
|
||||
if (hex_matches.size() == 2*sizeof(char_type)) {
|
||||
// This rule differs from the C/C++ standard, but ChaiScript
|
||||
// does not offer the same workaround options, and having
|
||||
// hexadecimal sequences longer than can fit into the char
|
||||
// type is undefined behavior anyway.
|
||||
process_hex();
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
process_hex();
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
assert_equal("\x39", "9")
|
||||
assert_equal("\x039", "9")
|
||||
assert_equal("\x39ec", "9ec")
|
||||
assert_equal("\x39g", "9g")
|
||||
assert_equal("b\x39g", "b9g")
|
||||
assert_equal("\x39\x38g", "98g")
|
||||
|
Loading…
x
Reference in New Issue
Block a user