diff --git a/lib/token.cpp b/lib/token.cpp index b11e12bf0a7..d1e76ebdd67 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1816,7 +1816,7 @@ void Token::printValueFlow(const std::vector& files, bool xml, std: outs += " valueType() && tok->valueType()->sign == ValueType::UNSIGNED) { + if (tok->valueType() && tok->valueType()->sign == ValueType::UNSIGNED && value.toString() != "!<=-1") { outs += "intvalue=\""; outs += MathLib::toString(static_cast(value.intvalue)); outs += '\"'; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 6efda65c11b..e981c8ea546 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -632,6 +632,8 @@ class TestSymbolDatabase : public TestFixture { TEST_CASE(stdintFunction); TEST_CASE(userDefinedLiteral); + + TEST_CASE(dumpValueNegative); // #14735 - dumping negative impossible value for unsigned expression } void array() { @@ -11444,6 +11446,18 @@ class TestSymbolDatabase : public TestFixture { ASSERT(!x->varId()); ASSERT(!x->variable()); } + + void dumpValueNegative() { // #14735 + GET_SYMBOL_DB("void f(unsigned int x) { a = x; }"); + const Token* x = Token::findsimplematch(tokenizer.tokens(), "x ;"); + ASSERT(x != nullptr); + std::ostringstream out; + x->printValueFlow({"test.cpp"}, true, out); + const std::string dump = out.str(); + const std::string expected = ""; + // dump should contain expected string, otherwise print the dump string + ASSERT_EQUALS(expected, dump.find(expected) == std::string::npos ? dump : expected); + } }; REGISTER_TEST(TestSymbolDatabase)