From 5458f843d41d8335fc6285d95eeb64a6ac0ddf06 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Wed, 12 Oct 2016 13:34:57 -0400 Subject: Changed parsing of hex escape sequences in Slice string literals --- cpp/src/Slice/Scanner.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'cpp/src/Slice/Scanner.cpp') diff --git a/cpp/src/Slice/Scanner.cpp b/cpp/src/Slice/Scanner.cpp index 27d362e04c9..62d1a7a6d85 100644 --- a/cpp/src/Slice/Scanner.cpp +++ b/cpp/src/Slice/Scanner.cpp @@ -1138,6 +1138,9 @@ YY_RULE_SETUP { case '\\': { + // + // add extra escape to our internal string + // str->v += '\\'; str->v += '\\'; break; @@ -1243,7 +1246,11 @@ YY_RULE_SETUP { IceUtil::Int64 value = 0; string escape = ""; - while(isxdigit(static_cast(next = static_cast(yyinput())))) + + // + // Unlike C++, we limit hex escape sequences to 2 hex digits + // + while(isxdigit(static_cast(next = static_cast(yyinput()))) && escape.length() < 2) { escape += next; } @@ -1256,16 +1263,11 @@ YY_RULE_SETUP { unit->error("illegal NUL character in string constant"); } - else if(value > 255) - { - ostringstream os; - os << "hex escape sequence out of range: '\\x" << hex << value << "'"; - unit->warning(os.str()); - } + assert(value >= 0 && value <= 255); str->v += static_cast(value); break; } - + // // Universal character name \unnnn code point U+nnnn // @@ -1367,12 +1369,10 @@ YY_RULE_SETUP ostringstream os; os << "unknown escape sequence '\\" << next << "'"; unit->warning(os.str()); - // - // We escape the backslack in a unknown escape sequence - // to keep compativility with 3.6" - // + + // Escape the \ in this unknown escape sequence + str->v += '\\'; str->v += '\\'; - str->v += c; unput(next); } } -- cgit v1.2.3