Skip to content

Commit 3feecc5

Browse files
authored
Fix 10988: FP: Regression, uninitvar (#4037)
1 parent ce35a6c commit 3feecc5

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

lib/checkuninitvar.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,8 @@ static ExprUsage getExprUsage(const Token* tok, int indirect, const Settings* se
15741574
if (indirect > 0 && tok->astParent()) {
15751575
if (Token::Match(tok->astParent(), "%assign%") && astIsRhs(tok))
15761576
return ExprUsage::NotUsed;
1577+
if (tok->astParent()->isConstOp())
1578+
return ExprUsage::NotUsed;
15771579
if (tok->astParent()->isCast())
15781580
return ExprUsage::NotUsed;
15791581
}

test/testuninitvar.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5247,6 +5247,44 @@ class TestUninitVar : public TestFixture {
52475247
" std::memcpy(&dest, &src, 1);\n"
52485248
"}\n");
52495249
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: &src\n", errout.str());
5250+
5251+
// #10988
5252+
valueFlowUninit("void f(const void* ptr, bool* result) {\n"
5253+
" int dummy;\n"
5254+
" *result = (&dummy < ptr);\n"
5255+
"}\n");
5256+
ASSERT_EQUALS("", errout.str());
5257+
5258+
valueFlowUninit("struct A {\n"
5259+
" int x;\n"
5260+
"};\n"
5261+
"void f() {\n"
5262+
" A a;\n"
5263+
" A* p = &a;\n"
5264+
" p->x = 1;\n"
5265+
"}\n");
5266+
ASSERT_EQUALS("", errout.str());
5267+
5268+
valueFlowUninit("struct A {\n"
5269+
" int x;\n"
5270+
"};\n"
5271+
"void g(const int&);\n"
5272+
"void f() {\n"
5273+
" A a;\n"
5274+
" g(a.x);\n"
5275+
"}\n");
5276+
ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: a.x\n", errout.str());
5277+
5278+
valueFlowUninit("struct A {\n"
5279+
" int x;\n"
5280+
"};\n"
5281+
"void g(const int&);\n"
5282+
"void f() {\n"
5283+
" A a;\n"
5284+
" A* p = &a;\n"
5285+
" g(p->x);\n"
5286+
"}\n");
5287+
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:8]: (error) Uninitialized variable: p->x\n", errout.str());
52505288
}
52515289

52525290
void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value

0 commit comments

Comments
 (0)