Fixed #3352 (False positive: member variable not initialized (3D array))
This commit is contained in:
parent
17f891ad34
commit
add2b3706b
|
@ -458,22 +458,17 @@ void CheckClass::initializeVarList(const Function &func, std::list<std::string>
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assignment of array item of member variable?
|
// Assignment of array item of member variable?
|
||||||
else if (Token::Match(ftok, "%var% [") &&
|
else if (Token::Match(ftok, "%var% [|.")) {
|
||||||
Token::simpleMatch(ftok->next()->link(), "] =")) {
|
const Token *tok2 = ftok;
|
||||||
assignVar(ftok->str(), scope, usage);
|
while (tok2) {
|
||||||
|
if (Token::simpleMatch(tok2->next(), "["))
|
||||||
|
tok2 = tok2->next()->link();
|
||||||
|
else if (Token::Match(tok2->next(), ". %var%"))
|
||||||
|
tok2 = tok2->tokAt(2);
|
||||||
|
else
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
if (Token::Match(tok2, "%any% ="))
|
||||||
// Assignment of member of array item of member variable?
|
|
||||||
else if (Token::Match(ftok, "%var% [ ") &&
|
|
||||||
(Token::Match(ftok->next()->link(), "] . %var% =") ||
|
|
||||||
Token::Match(ftok->next()->link(), "] . %var% . %var% ="))) {
|
|
||||||
assignVar(ftok->str(), scope, usage);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assignment of array item of member variable?
|
|
||||||
else if (Token::Match(ftok, "%var% [") &&
|
|
||||||
Token::simpleMatch(ftok->next()->link(), "] [") &&
|
|
||||||
Token::simpleMatch(ftok->next()->link()->next()->link(), "] =")) {
|
|
||||||
assignVar(ftok->str(), scope, usage);
|
assignVar(ftok->str(), scope, usage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,11 +477,6 @@ void CheckClass::initializeVarList(const Function &func, std::list<std::string>
|
||||||
assignVar(ftok->next()->str(), scope, usage);
|
assignVar(ftok->next()->str(), scope, usage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assignment of struct member of member variable?
|
|
||||||
else if (Token::Match(ftok, "%var% . %any% =")) {
|
|
||||||
assignVar(ftok->str(), scope, usage);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The functions 'clear' and 'Clear' are supposed to initialize variable.
|
// The functions 'clear' and 'Clear' are supposed to initialize variable.
|
||||||
if (Token::Match(ftok, "%var% . clear|Clear (")) {
|
if (Token::Match(ftok, "%var% . clear|Clear (")) {
|
||||||
assignVar(ftok->str(), scope, usage);
|
assignVar(ftok->str(), scope, usage);
|
||||||
|
|
|
@ -77,6 +77,7 @@ private:
|
||||||
TEST_CASE(uninitVarArray6);
|
TEST_CASE(uninitVarArray6);
|
||||||
TEST_CASE(uninitVarArray7);
|
TEST_CASE(uninitVarArray7);
|
||||||
TEST_CASE(uninitVarArray2D);
|
TEST_CASE(uninitVarArray2D);
|
||||||
|
TEST_CASE(uninitVarArray3D);
|
||||||
TEST_CASE(uninitVarStruct1); // ticket #2172
|
TEST_CASE(uninitVarStruct1); // ticket #2172
|
||||||
TEST_CASE(uninitVarStruct2); // ticket #838
|
TEST_CASE(uninitVarStruct2); // ticket #838
|
||||||
TEST_CASE(uninitMissingFuncDef); // can't expand function in constructor
|
TEST_CASE(uninitMissingFuncDef); // can't expand function in constructor
|
||||||
|
@ -2433,6 +2434,17 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uninitVarArray3D() {
|
||||||
|
checkUninitVar("class John\n"
|
||||||
|
"{\n"
|
||||||
|
"private:\n"
|
||||||
|
" char a[2][2][2];\n"
|
||||||
|
"public:\n"
|
||||||
|
" John() { a[0][0][0] = 0; }\n"
|
||||||
|
"};\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void uninitVarStruct1() { // ticket #2172
|
void uninitVarStruct1() { // ticket #2172
|
||||||
checkUninitVar("class A\n"
|
checkUninitVar("class A\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue