strutils::unescape(): fix off-by-one error
An octal escape sequence in a string literal can't have more than 3 octal digits after the backslash. The previous code was using up to 4 digits per octal escape sequence.
This commit is contained in:
@@ -674,7 +674,7 @@ std::string unescape(const char* s)
|
||||
|
||||
} else if (*s >= '0' && *s <= '7') {
|
||||
int v = *s++ - '0';
|
||||
for (int i = 0; i < 3 && *s >= '0' && *s <= '7'; i++, s++)
|
||||
for (int i = 0; i < 2 && *s >= '0' && *s <= '7'; i++, s++)
|
||||
v = v * 8 + *s - '0';
|
||||
r += v;
|
||||
continue;
|
||||
|
||||
@@ -142,6 +142,8 @@ void test_split()
|
||||
void test_unescape()
|
||||
{
|
||||
SG_CHECK_EQUAL(strutils::unescape("\\ \\n\\t\\x41\\117a"), " \n\tAOa");
|
||||
// Two chars: '\033' (ESC) followed by '2'
|
||||
SG_CHECK_EQUAL(strutils::unescape("\\0332"), "\0332");
|
||||
}
|
||||
|
||||
void test_compare_versions()
|
||||
|
||||
Reference in New Issue
Block a user