diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index 6d98cbea9..dcccbe818 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -356,6 +356,8 @@ MathLib::bigint MathLib::characterLiteralToLongNumber(const std::string& str) // is implementation-defined. // clang and gcc seem to use the following encoding: 'AB' as (('A' << 8) | 'B') const std::string& normStr = normalizeCharacterLiteral(str); + if (normStr.empty()) + throw InternalError(0, "Internal Error. MathLib::characterLiteralToLongNumber: Unhandled char constant '" + str + "'."); return encodeMultiChar(normStr); } diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index 8cc7258d1..ca569e103 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -301,6 +301,7 @@ private: ASSERT_EQUALS(0, MathLib::characterLiteralToLongNumber(std::string(""))); ASSERT_EQUALS(32, MathLib::characterLiteralToLongNumber(std::string(" "))); ASSERT_EQUALS(538976288, MathLib::characterLiteralToLongNumber(std::string(" "))); + ASSERT_THROW(MathLib::characterLiteralToLongNumber(std::string("\\u")), InternalError); } ASSERT_EQUALS(-8552249625308161526, MathLib::toLongNumber("0x89504e470d0a1a0a"));