Skip to content
Open
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/vf_analyzers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ struct ValueFlowAnalyzer : Analyzer {
if (inconclusive)
return Action::Read | Action::Inconclusive;
if (isVariableChanged(tok, getIndirect(tok), getSettings())) {
if (Token::Match(tok->astParent(), "*|[|.|++|--"))
if (Token::Match(tok->astParent(), "*|[|.|++|--") ||
(Token::Match(tok->astParent(), "%assign%") && tok->astParent()->str().size() > 1)) // compound assignment
return Action::Read | Action::Invalid;
// Check if its assigned to the same value
if (value && !value->isImpossible() && Token::simpleMatch(tok->astParent(), "=") && astIsLHS(tok) &&
Expand Down
2 changes: 1 addition & 1 deletion test/testnullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4707,7 +4707,7 @@ class TestNullPointer : public TestFixture {
" p += a;\n"
" *p = 0;\n"
"}\n");
ASSERT_EQUALS("", errout_str());
ASSERT_EQUALS("[test.cpp:2:7]: (error) Pointer addition with NULL pointer. [nullPointerArithmetic]\n", errout_str());

check("int f(int *p = 0) {\n"
" if (p == 0) {\n"
Expand Down
9 changes: 9 additions & 0 deletions test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6846,6 +6846,15 @@ class TestUninitVar : public TestFixture {
" return a[0];\n"
"}\n");
ASSERT_EQUALS("", errout_str());

valueFlowUninit("void f(int i) {\n"
" int x, y;\n"
" x += i;\n"
" y <<= i;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3:5]: (error) Uninitialized variable: x [uninitvar]\n"
"[test.cpp:4:5]: (error) Uninitialized variable: y [uninitvar]\n",
errout_str());
}

void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value
Expand Down
16 changes: 16 additions & 0 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,22 @@ class TestValueFlow : public TestFixture {
" g(std::move(x)).f(1);\n"
"}\n";
ASSERT_EQUALS(false, testValueOfX(code, 5U, ValueFlow::Value::MoveKind::MovedVariable));

code = "void f(std::string x) {\n" // #15155
" std::string a{ std::move(x) };\n"
" x += \"abc\";\n"
"}\n";
ASSERT_EQUALS(true, testValueOfX(code, 3U, ValueFlow::Value::MoveKind::MovedVariable));

code = "struct S {\n"
" S& operator<<=(int i);\n"
" std::string m;\n"
"};\n"
"void f(S x) {\n"
" S a{ std::move(x) };\n"
" x <<= 5;\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 7U, ValueFlow::Value::MoveKind::MovedVariable));
}

void valueFlowCalculations() {
Expand Down
Loading