Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,7 @@ void Token::printValueFlow(const std::vector<std::string>& files, bool xml, std:
outs += " <value ";
switch (value.valueType) {
case ValueFlow::Value::ValueType::INT:
if (tok->valueType() && tok->valueType()->sign == ValueType::UNSIGNED) {
if (tok->valueType() && tok->valueType()->sign == ValueType::UNSIGNED && value.toString() != "!<=-1") {
outs += "intvalue=\"";
outs += MathLib::toString(static_cast<MathLib::biguint>(value.intvalue));
outs += '\"';
Expand Down
14 changes: 14 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 = "<value intvalue=\"-1\" bound=\"Upper\" impossible=\"true\" path=\"0\"/>";
// dump should contain expected string, otherwise print the dump string
ASSERT_EQUALS(expected, dump.find(expected) == std::string::npos ? dump : expected);
}
};

REGISTER_TEST(TestSymbolDatabase)
Loading