From fee0e4edfa999325c757f25a7d08b74790545c5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 28 Aug 2016 11:37:05 +0200 Subject: [PATCH] Fixed #7177 (MathLib: Does not handle '\xF6' properly) --- lib/mathlib.cpp | 7 ++++++- test/testmathlib.cpp | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index b681c61ef..7ed5b8830 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -349,7 +349,12 @@ static unsigned int encodeMultiChar(const std::string& str) MathLib::bigint MathLib::characterLiteralToLongNumber(const std::string& str) { if (str.empty()) - return 0; // for unit-testing... + return 0; // <- only possible in unit testing + + // '\xF6' + if (str.size() == 4 && str.compare(0,2,"\\x")==0 && std::isxdigit(str[2]) && std::isxdigit(str[3])) { + return std::strtoul(str.substr(2).c_str(), NULL, 16); + } // C99 6.4.4.4 // The value of an integer character constant containing more than one character (e.g., 'ab'), diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index 773ab2b4d..ecdf5eec2 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -292,6 +292,7 @@ private: ASSERT_EQUALS((int)('\3'), MathLib::toLongNumber("'\\3'")); ASSERT_EQUALS((int)('\34'), MathLib::toLongNumber("'\\34'")); ASSERT_EQUALS((int)('\034'), MathLib::toLongNumber("'\\034'")); + ASSERT_EQUALS((int)('\x34'), MathLib::toLongNumber("'\\x34'")); ASSERT_EQUALS((int)('\134'), MathLib::toLongNumber("'\\134'")); ASSERT_EQUALS((int)('\134t'), MathLib::toLongNumber("'\\134t'")); // Ticket #7452 ASSERT_THROW(MathLib::toLongNumber("'\\9'"), InternalError);