diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index 2e2fe2f43..a626b51e8 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -528,7 +528,14 @@ MathLib::bigint MathLib::toLongNumber(const std::string & str) return characterLiteralToLongNumber(str.substr(1,str.size()-2)); } - bigint ret = 0; + if (str[0] == '-') { + bigint ret = 0; + std::istringstream istr(str); + istr >> ret; + return ret; + } + + biguint ret = 0; std::istringstream istr(str); istr >> ret; return ret; diff --git a/lib/token.cpp b/lib/token.cpp index fb13e346c..fe1f6c8c4 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1355,7 +1355,10 @@ void Token::printValueFlow(bool xml, std::ostream &out) const out << " valueType) { case ValueFlow::Value::INT: - out << "intvalue=\"" << it->intvalue << '\"'; + if (tok->valueType() && tok->valueType()->sign == ValueType::UNSIGNED) + out << "intvalue=\"" << (MathLib::biguint)it->intvalue << '\"'; + else + out << "intvalue=\"" << it->intvalue << '\"'; break; case ValueFlow::Value::TOK: out << "tokvalue=\"" << it->tokvalue << '\"'; @@ -1384,7 +1387,10 @@ void Token::printValueFlow(bool xml, std::ostream &out) const out << ","; switch (it->valueType) { case ValueFlow::Value::INT: - out << it->intvalue; + if (tok->valueType() && tok->valueType()->sign == ValueType::UNSIGNED) + out << (MathLib::biguint)it->intvalue; + else + out << it->intvalue; break; case ValueFlow::Value::TOK: out << it->tokvalue->str(); diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index f0687a956..7751b11c9 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -242,6 +242,7 @@ private: ASSERT_EQUALS(0, valueOfTok("x(NULL);", "NULL").intvalue); ASSERT_EQUALS((int)('a'), valueOfTok("x='a';", "'a'").intvalue); ASSERT_EQUALS((int)('\n'), valueOfTok("x='\\n';", "'\\n'").intvalue); + ASSERT_EQUALS(18446744069414584320, valueOfTok("x=0xFFFFFFFF00000000;","18446744069414584320U").intvalue); // #7701 } void valueFlowString() {