Skip to content

Commit eeb0126

Browse files
Fix #12932 FP: uninitvar (use iterators of std::array of size 0) (#6602)
1 parent 03ac57e commit eeb0126

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/checkuninitvar.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,11 @@ void CheckUninitVar::valueFlowUninit()
16411641
const bool isarray = tok->variable()->isArray();
16421642
if (isarray && tok->variable()->isMember())
16431643
continue; // Todo: this is a bailout
1644+
if (isarray && tok->variable()->isStlType() && Token::simpleMatch(tok->astParent(), ".")) {
1645+
const auto yield = astContainerYield(tok);
1646+
if (yield != Library::Container::Yield::AT_INDEX && yield != Library::Container::Yield::ITEM)
1647+
continue;
1648+
}
16441649
const bool deref = CheckNullPointer::isPointerDeRef(tok, unknown, *mSettings);
16451650
uninitderef = deref && v->indirect == 0;
16461651
const bool isleaf = isLeafDot(tok) || uninitderef;

test/testuninitvar.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6542,6 +6542,17 @@ class TestUninitVar : public TestFixture {
65426542
"[test.cpp:12]: (error) Uninitialized variable: b\n"
65436543
"[test.cpp:16]: (error) Uninitialized variable: a\n",
65446544
errout_str());
6545+
6546+
valueFlowUninit("void f() {\n" // # 12932
6547+
" std::array<int, 0> a;\n"
6548+
" if (a.begin() == a.end()) {}\n"
6549+
" std::array<int, 1> b;\n"
6550+
" auto it = b.begin();\n"
6551+
" *it = 0;\n"
6552+
" std::array<int, 1> c;\n"
6553+
" return c.front();\n"
6554+
"}\n");
6555+
ASSERT_EQUALS("[test.cpp:8]: (error) Uninitialized variable: c\n", errout_str());
65456556
}
65466557

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

0 commit comments

Comments
 (0)