Fixed #6646 (False positive uninitvar - loopvariable initialized inside loop)
This commit is contained in:
parent
0bec604627
commit
9711064b74
|
@ -101,6 +101,10 @@ void CheckUninitVar::checkScope(const Scope* scope)
|
|||
if (!tok)
|
||||
continue;
|
||||
|
||||
if (tok->astParent() && Token::simpleMatch(tok->astParent()->previous(), "for (") &&
|
||||
checkLoopBody(tok->astParent()->link()->next(), *i, i->isArray() ? ARRAY : NO_ALLOC, "", true))
|
||||
continue;
|
||||
|
||||
if (i->isArray()) {
|
||||
Alloc alloc = ARRAY;
|
||||
checkScopeForVariable(tok, *i, nullptr, nullptr, &alloc, "");
|
||||
|
|
|
@ -3541,6 +3541,19 @@ private:
|
|||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #6646 - init in for loop
|
||||
checkUninitVar("void f() {\n" // No FP
|
||||
" for (int i;;i++)\n"
|
||||
" dostuff(&i);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar("void f() {\n" // No FN
|
||||
" for (int i;;i++)\n"
|
||||
" a=i;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: i\n", errout.str());
|
||||
}
|
||||
|
||||
void uninitvar2_4494() {
|
||||
|
|
Loading…
Reference in New Issue