Commit 209bad42 authored by hjk's avatar hjk

Debugger: Fix reading of \x escape sequences in strings

Change-Id: Idfe41f6c2769397d6eee3ab74de4afbb94111e25
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 24b8ef31
......@@ -38,6 +38,17 @@
namespace Debugger {
namespace Internal {
uchar fromhex(uchar c)
{
if (c >= '0' && c <= '9')
return c - '0';
if (c >= 'a' && c <= 'z')
return 10 + c - 'a';
if (c >= 'A' && c <= 'Z')
return 10 + c - 'A';
return -1;
}
void skipCommas(const char *&from, const char *to)
{
while (*from == ',' && from != to)
......@@ -120,6 +131,26 @@ QByteArray GdbMi::parseCString(const char *&from, const char *to)
case 'v': *dst++ = '\v'; break;
case '"': *dst++ = '"'; break;
case '\\': *dst++ = '\\'; break;
case 'x': {
c = *src++;
int chars = 0;
uchar prod = 0;
while (true) {
uchar val = fromhex(c);
if (val == uchar(-1))
break;
prod = prod * 16 + val;
if (++chars == 3 || src == end)
break;
c = *src++;
}
if (!chars) {
qDebug() << "MI Parse Error, unrecognized hex escape";
return QByteArray();
}
*dst++ = prod;
break;
}
default:
{
int chars = 0;
......
......@@ -1056,8 +1056,8 @@ void tst_Dumpers::dumper_data()
QTest::newRow("QByteArray3")
<< Data("#include <QByteArray>\n",
"const char *str1 = \"\356\";\n"
"const char *str2 = \"\xee\";\n"
"const char *str1 = \"\\356\";\n"
"const char *str2 = \"\\xee\";\n"
"const char *str3 = \"\\\\ee\";\n"
"QByteArray buf1(str1);\n"
"QByteArray buf2(str2);\n"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment