fix #2792 (false positive: Member variable 'class::m_val' is not assigned a value in 'class::operator=')

This commit is contained in:
Robert Reif 2011-05-24 20:25:34 -04:00
parent 287840e6bc
commit 42316f3e0b
2 changed files with 27 additions and 1 deletions

View File

@ -308,7 +308,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<std::string>
ftok = ftok->next();
// Using the operator= function to initialize all variables..
if (Token::simpleMatch(ftok->next(), "* this ="))
if (Token::Match(ftok->next(), "return| * this ="))
{
assignAllVar(usage);
break;

View File

@ -63,6 +63,7 @@ private:
TEST_CASE(uninitVar16);
TEST_CASE(uninitVar17);
TEST_CASE(uninitVar18); // ticket #2465
TEST_CASE(uninitVar19); // ticket #2792
TEST_CASE(uninitVarEnum);
TEST_CASE(uninitVarStream);
TEST_CASE(uninitVarTypedef);
@ -2183,6 +2184,31 @@ private:
ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable 'A::value' is not initialized in the constructor.\n", errout.str());
}
void uninitVar19() // ticket #2792
{
checkUninitVar("class mystring\n"
"{\n"
" char* m_str;\n"
" int m_len;\n"
"public:\n"
" mystring(const char* str)\n"
" {\n"
" m_len = strlen(str);\n"
" m_str = (char*) malloc(m_len+1);\n"
" memcpy(m_str, str, m_len+1);\n"
" }\n"
" mystring& operator=(const mystring& copy)\n"
" {\n"
" return (*this = copy.m_str);\n"
" }\n"
" ~mystring()\n"
" {\n"
" free(m_str);\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void uninitVarArray1()
{
checkUninitVar("class John\n"