summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/Scanner.cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2016-10-12 13:34:57 -0400
committerBernard Normier <bernard@zeroc.com>2016-10-12 13:34:57 -0400
commit5458f843d41d8335fc6285d95eeb64a6ac0ddf06 (patch)
treec030221d4c9fe8bfdfffbc7974869e9eb90807b6 /cpp/src/Slice/Scanner.cpp
parentMerge pull request #11 from grembo/patch-1 (diff)
downloadice-5458f843d41d8335fc6285d95eeb64a6ac0ddf06.tar.bz2
ice-5458f843d41d8335fc6285d95eeb64a6ac0ddf06.tar.xz
ice-5458f843d41d8335fc6285d95eeb64a6ac0ddf06.zip
Changed parsing of hex escape sequences in Slice string literals
Diffstat (limited to 'cpp/src/Slice/Scanner.cpp')
-rw-r--r--cpp/src/Slice/Scanner.cpp26
1 files changed, 13 insertions, 13 deletions
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<unsigned char>(next = static_cast<char>(yyinput()))))
+
+ //
+ // Unlike C++, we limit hex escape sequences to 2 hex digits
+ //
+ while(isxdigit(static_cast<unsigned char>(next = static_cast<char>(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<char>(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);
}
}