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
3 changes: 2 additions & 1 deletion lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7258,7 +7258,8 @@ struct MultiValueFlowAnalyzer : ValueFlowAnalyzer {
}

bool stopOnCondition(const Token* /*condTok*/) const override {
return isConditional();
// TODO fix false negatives
return true; // isConditional();
}

bool updateScope(const Token* endBlock, bool /*modified*/) const override {
Expand Down
11 changes: 6 additions & 5 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2386,11 +2386,12 @@ class TestStl : public TestFixture {
"void g(const std::vector<int>& w) {\n"
" f(-1, w);\n"
"}\n");
ASSERT_EQUALS("test.cpp:5:warning:Array index -1 is out of bounds.\n"
"test.cpp:8:note:Calling function 'f', 1st argument '-1' value is -1\n"
"test.cpp:3:note:Assuming condition is false\n"
"test.cpp:5:note:Negative array index\n",
errout.str());
TODO_ASSERT_EQUALS("test.cpp:5:warning:Array index -1 is out of bounds.\n"
"test.cpp:8:note:Calling function 'f', 1st argument '-1' value is -1\n"
"test.cpp:3:note:Assuming condition is false\n"
"test.cpp:5:note:Negative array index\n",
"",
errout.str());

settings = oldSettings;
}
Expand Down
2 changes: 1 addition & 1 deletion test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6490,7 +6490,7 @@ class TestUninitVar : public TestFixture {
" bool copied_all = true;\n"
" g(&copied_all, 5, 6, &bytesCopied);\n"
"}");
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:2]: (warning) Uninitialized variable: *buflen\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:2]: (warning) Uninitialized variable: *buflen\n", "", errout.str());

// # 9953
valueFlowUninit("uint32_t f(uint8_t *mem) {\n"
Expand Down
16 changes: 15 additions & 1 deletion test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4517,7 +4517,7 @@ class TestValueFlow : public TestFixture {
"void f(Object *obj) {\n"
" if (valid(obj, K0)) {}\n"
"}\n";
ASSERT_EQUALS(true, testValueOfX(code, 7U, 0));
TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 7U, 0));
ASSERT_EQUALS(false, testValueOfXKnown(code, 7U, 0));

code = "int f(int i) {\n"
Expand All @@ -4530,7 +4530,21 @@ class TestValueFlow : public TestFixture {
"}\n";
ASSERT_EQUALS(true, testValueOfX(code, 3U, 1));
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));

code = "void foo(int* p, int* x) {\n"
" bool b1 = (p != NULL);\n"
" bool b2 = b1 && (x != NULL);\n"
" if (b2) {\n"
" *x = 3;\n"
" }\n"
"}\n"
"\n"
"void bar() {\n"
" foo(NULL, NULL);\n"
"}\n";
ASSERT_EQUALS(false, testValueOfX(code, 5U, 0));
}

void valueFlowFunctionReturn() {
const char *code;

Expand Down