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: 2 additions & 0 deletions lib/vf_analyzers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ struct ValueFlowAnalyzer : Analyzer {
continue;
if (exact && v.intvalue != 0 && !isPoint)
continue;
if (astIsUnsigned(tok) != astIsUnsigned(v.tokvalue))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, it is a little too restrictive which could lead to FNs, but it will fix FPs. To fix FNs, we would need to check if the value is within the range of an unsigned value. I am not sure how to write a test case to demonstrate it though as most known values will be passed through with the afterAssign passes anyways. Need to think about it some more.

@chrchr-github chrchr-github Jan 7, 2025

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 We could also wait until after the next release, so we can see the effects in daca.

continue;
std::vector<MathLib::bigint> r;
ValueFlow::Value::Bound bound = currValue->bound;
if (match(v.tokvalue)) {
Expand Down
7 changes: 7 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4947,6 +4947,13 @@ class TestCondition : public TestFixture {
" }\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("void f(unsigned x) {\n" // #13522
" unsigned u = x;\n"
" int i = u - 0;\n"
" if (i < 0) {}\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void alwaysTrueInfer() {
Expand Down