MathLib: fix for octal char literal '\200'

This commit is contained in:
Daniel Marjamäki 2016-10-16 13:42:20 +02:00
parent 5175bf88d6
commit 90ed7634b8
2 changed files with 12 additions and 0 deletions

View File

@ -346,6 +346,10 @@ static unsigned int encodeMultiChar(const std::string& str)
return retval; return retval;
} }
static bool isoctal(int c) {
return c>='0' && c<='7';
}
MathLib::bigint MathLib::characterLiteralToLongNumber(const std::string& str) MathLib::bigint MathLib::characterLiteralToLongNumber(const std::string& str)
{ {
if (str.empty()) if (str.empty())
@ -356,6 +360,11 @@ MathLib::bigint MathLib::characterLiteralToLongNumber(const std::string& str)
return std::strtoul(str.substr(2).c_str(), NULL, 16); return std::strtoul(str.substr(2).c_str(), NULL, 16);
} }
// '\123'
if (str.size() == 4 && str[0] == '\\' && isoctal(str[1]) && isoctal(str[2]) && isoctal(str[3])) {
return (char)std::strtoul(str.substr(1).c_str(), NULL, 8);
}
// C99 6.4.4.4 // C99 6.4.4.4
// The value of an integer character constant containing more than one character (e.g., 'ab'), // The value of an integer character constant containing more than one character (e.g., 'ab'),
// or containing a character or escape sequence that does not map to a single-byte execution character, // or containing a character or escape sequence that does not map to a single-byte execution character,

View File

@ -275,6 +275,9 @@ private:
// from char // from char
ASSERT_EQUALS((int)('A'), MathLib::toLongNumber("'A'")); ASSERT_EQUALS((int)('A'), MathLib::toLongNumber("'A'"));
ASSERT_EQUALS((int)('\x10'), MathLib::toLongNumber("'\\x10'"));
ASSERT_EQUALS((int)('\100'), MathLib::toLongNumber("'\\100'"));
ASSERT_EQUALS((int)('\200'), MathLib::toLongNumber("'\\200'"));
#ifdef __GNUC__ #ifdef __GNUC__
// BEGIN Implementation-specific results // BEGIN Implementation-specific results
ASSERT_EQUALS((int)('AB'), MathLib::toLongNumber("'AB'")); ASSERT_EQUALS((int)('AB'), MathLib::toLongNumber("'AB'"));