Skip to content

Commit 23a103d

Browse files
committed
Fixed #14735 (dumpfile: Value::intvalue with negative value for unsigned expression)
1 parent ce9227f commit 23a103d

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

lib/token.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ void Token::printValueFlow(const std::vector<std::string>& files, bool xml, std:
18161816
outs += " <value ";
18171817
switch (value.valueType) {
18181818
case ValueFlow::Value::ValueType::INT:
1819-
if (tok->valueType() && tok->valueType()->sign == ValueType::UNSIGNED) {
1819+
if (tok->valueType() && tok->valueType()->sign == ValueType::UNSIGNED && value.toString() != "!<=-1") {
18201820
outs += "intvalue=\"";
18211821
outs += MathLib::toString(static_cast<MathLib::biguint>(value.intvalue));
18221822
outs += '\"';

test/testsymboldatabase.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,8 @@ class TestSymbolDatabase : public TestFixture {
632632
TEST_CASE(stdintFunction);
633633

634634
TEST_CASE(userDefinedLiteral);
635+
636+
TEST_CASE(dumpValueNegative); // dumping negative impossible value
635637
}
636638

637639
void array() {
@@ -11444,6 +11446,18 @@ class TestSymbolDatabase : public TestFixture {
1144411446
ASSERT(!x->varId());
1144511447
ASSERT(!x->variable());
1144611448
}
11449+
11450+
void dumpValueNegative() { // #14735
11451+
GET_SYMBOL_DB("void f(unsigned int x) { a = x; }");
11452+
const Token* x = Token::findsimplematch(tokenizer.tokens(), "x ;");
11453+
ASSERT(x != nullptr);
11454+
std::ostringstream out;
11455+
x->printValueFlow({"test.cpp"}, true, out);
11456+
const std::string dump = out.str();
11457+
const std::string expected = "<value intvalue=\"-1\" bound=\"Upper\" impossible=\"true\" path=\"0\"/>";
11458+
// dump should contain expected string, otherwise print the dump string
11459+
ASSERT_EQUALS(expected, dump.find(expected) == std::string::npos ? dump : expected);
11460+
}
1144711461
};
1144811462

1144911463
REGISTER_TEST(TestSymbolDatabase)

0 commit comments

Comments
 (0)