diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index a17d8ec86..44f1de849 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -54,6 +54,9 @@ MathLib::value::value(const std::string &s) : type = MathLib::value::INT; intValue = MathLib::toLongNumber(s); + if (isIntHex(s) && intValue < 0) + isUnsigned = true; + // read suffix if (s.size() >= 2U) { for (std::size_t i = s.size() - 1U; i > 0U; --i) { @@ -93,9 +96,10 @@ std::string MathLib::value::str() const return ret.substr(0, pos+1); } - ostr << intValue; if (isUnsigned) - ostr << "U"; + ostr << static_cast(intValue) << "U"; + else + ostr << intValue; if (type == MathLib::value::LONG) ostr << "L"; else if (type == MathLib::value::LONGLONG) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 77eeb687e..2128cfb5b 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -129,9 +129,7 @@ void TokenList::addtoken(std::string str, const unsigned int lineno, const unsig // Replace hexadecimal value with decimal if (MathLib::isIntHex(str) || MathLib::isOct(str) || MathLib::isBin(str)) { - std::ostringstream str2stream; - str2stream << MathLib::toULongNumber(str); - str = str2stream.str(); + str = MathLib::value(str).str(); } else if (str.compare(0, 5, "_Bool") == 0) { str = "bool"; } diff --git a/test/testother.cpp b/test/testother.cpp index b9b84373f..dc6ff7f7b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5745,11 +5745,7 @@ private: check("void f(unsigned long long ull) {\n" " if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\n" "}\n"); -#if defined(_MSC_VER) && defined(_M_AMD64) - TODO_ASSERT_EQUALS("", "[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '||'.\n", errout.str()); -#else ASSERT_EQUALS("", errout.str()); -#endif } void redundantPointerOp() { diff --git a/test/testtokenlist.cpp b/test/testtokenlist.cpp index 999a61d4b..ac0a2296a 100644 --- a/test/testtokenlist.cpp +++ b/test/testtokenlist.cpp @@ -45,7 +45,7 @@ private: const std::string code = "0x89504e470d0a1a0a"; TokenList tokenlist(&settings); tokenlist.addtoken(code, 1, 1, false); - ASSERT_EQUALS("9894494448401390090", tokenlist.front()->str()); + ASSERT_EQUALS("9894494448401390090U", tokenlist.front()->str()); // that is supposed to break on 32bit //unsigned long numberUL(0); //std::istringstream(tokenlist.front()->str()) >> numberUL;