Skip to content

Commit 5bb98e0

Browse files
committed
Fix 13755: false negative: accessMoved with usage through dereference
1 parent 04c885d commit 5bb98e0

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

lib/vf_analyzers.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@
4747
#include <set>
4848
#include <type_traits>
4949

50+
static bool isDereferenceOp(const Token* tok)
51+
{
52+
if(!tok)
53+
return false;
54+
if(!tok->astOperand1())
55+
return false;
56+
if(tok->str() == "*")
57+
return true;
58+
return tok->str() == "." && tok->originalName() == "->";
59+
}
60+
5061
struct ValueFlowAnalyzer : Analyzer {
5162
const Settings& settings;
5263
ProgramMemoryState pms;
@@ -586,7 +597,7 @@ struct ValueFlowAnalyzer : Analyzer {
586597
} else {
587598
return analyzeMatch(tok, d) | Action::Match;
588599
}
589-
} else if (ref->isUnaryOp("*") && !match(ref->astOperand1())) {
600+
} else if (isDereferenceOp(ref) && !match(ref->astOperand1())) {
590601
const Token* lifeTok = nullptr;
591602
for (const ValueFlow::Value& v:ref->astOperand1()->values()) {
592603
if (!v.isLocalLifetimeValue())

test/testother.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ class TestOther : public TestFixture {
278278
TEST_CASE(moveAndReference);
279279
TEST_CASE(moveForRange);
280280
TEST_CASE(moveTernary);
281+
TEST_CASE(movePointerAlias);
281282

282283
TEST_CASE(funcArgNamesDifferent);
283284
TEST_CASE(funcArgOrderDifferent);
@@ -12114,6 +12115,17 @@ class TestOther : public TestFixture {
1211412115
ASSERT_EQUALS("", errout_str());
1211512116
}
1211612117

12118+
void movePointerAlias()
12119+
{
12120+
check("void f() {\n"
12121+
" std::string s;\n"
12122+
" std::string s1 = std::move(s);\n"
12123+
" const std::string* s_p = &s;\n"
12124+
" s_p->size();\n"
12125+
"}\n");
12126+
ASSERT_EQUALS("[test.cpp:5]: (warning) Access of moved variable '.'.\n", errout_str());
12127+
}
12128+
1211712129
void funcArgNamesDifferent() {
1211812130
check("void func1(int a, int b, int c);\n"
1211912131
"void func1(int a, int b, int c) { }\n"

test/testuninitvar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6161,7 +6161,7 @@ class TestUninitVar : public TestFixture {
61616161
" A* p = &a;\n"
61626162
" g(p->x);\n"
61636163
"}\n");
6164-
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:8]: (error) Uninitialized variable: p->x\n", errout_str());
6164+
ASSERT_EQUALS("[test.cpp:8]: (error) Uninitialized variable: p->x\n", errout_str());
61656165

61666166
valueFlowUninit("void f() {\n"
61676167
" int a;\n"

0 commit comments

Comments
 (0)