Fixed #1376 (Member variable not initialized in the constructor false positive)

This commit is contained in:
Daniel Marjamäki 2010-02-10 19:28:51 +01:00
parent faced1b483
commit 0a6aa0f094
2 changed files with 27 additions and 0 deletions

View File

@ -277,6 +277,14 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *va
break;
}
// Clearing array..
else if (Token::Match(ftok, "memset ( %var% ,"))
{
initVar(varlist, ftok->strAt(2));
ftok = ftok->next()->link();
continue;
}
// Calling member function?
else if (Token::Match(ftok, "%var% ("))
{

View File

@ -51,6 +51,7 @@ private:
TEST_CASE(uninitVarTypedef);
TEST_CASE(uninitVarArray1);
TEST_CASE(uninitVarArray2);
TEST_CASE(uninitVarArray3);
TEST_CASE(uninitVarArray2D);
TEST_CASE(uninitMissingFuncDef);// can't expand function in constructor
TEST_CASE(privateCtor1); // If constructor is private..
@ -1136,6 +1137,24 @@ private:
ASSERT_EQUALS("", errout.str());
}
void uninitVarArray3()
{
checkUninitVar("class John\n"
"{\n"
"private:\n"
" int a[100];\n"
" int b[100];\n"
"\n"
"public:\n"
" John()\n"
" {\n"
" memset(a,0,sizeof(a));\n"
" memset(b,0,sizeof(b));\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void uninitVarArray2D()
{
checkUninitVar("class John\n"