From 90ed7634b83482843daa644bef5280048341c367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 16 Oct 2016 13:42:20 +0200 Subject: [PATCH] MathLib: fix for octal char literal '\200' --- lib/mathlib.cpp | 9 +++++++++ test/testmathlib.cpp | 3 +++ 2 files changed, 12 insertions(+) diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index 7ed5b8830..fbdf0dbc2 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -346,6 +346,10 @@ static unsigned int encodeMultiChar(const std::string& str) return retval; } +static bool isoctal(int c) { + return c>='0' && c<='7'; +} + MathLib::bigint MathLib::characterLiteralToLongNumber(const std::string& str) { 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); } + // '\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 // 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, diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index ecdf5eec2..82d80d428 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -275,6 +275,9 @@ private: // from char 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__ // BEGIN Implementation-specific results ASSERT_EQUALS((int)('AB'), MathLib::toLongNumber("'AB'"));