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:
Christian Kaeser 2015-11-08 18:36:16 +01:00
parent 34c6b17215
commit 202204a82a
2 changed files with 9 additions and 1 deletions

View File

@ -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();

View File

@ -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")