Uninitialized variable: chained assignments

This commit is contained in:
Daniel Marjamäki 2008-11-13 18:16:36 +00:00
parent 34507f73ce
commit 4995c5d4c6
2 changed files with 38 additions and 16 deletions

View File

@ -100,16 +100,16 @@ struct VAR *CheckClass::ClassChecking_GetVarList(const TOKEN *tok1)
return varlist;
}
//---------------------------------------------------------------------------
CheckClass::CheckClass( Tokenizer *tokenizer )
{
_tokenizer = tokenizer;
}
CheckClass::~CheckClass()
{
}
CheckClass::CheckClass( Tokenizer *tokenizer )
{
_tokenizer = tokenizer;
}
CheckClass::~CheckClass()
{
}
const TOKEN * CheckClass::FindClassFunction( const TOKEN *tok, const char classname[], const char funcname[], int &indentlevel )
{
@ -243,8 +243,8 @@ void CheckClass::ClassChecking_VarList_Initialize(const TOKEN *tok1, const TOKEN
if ( indentlevel < 1 )
continue;
// Before a new statement there is "[{};)]" or "else"
if ( ! Match(ftok, "[{};)]") && ! Match(ftok, "else") )
// Before a new statement there is "[{};)=]" or "else"
if ( ! Match(ftok, "[{};)=]") && ! Match(ftok, "else") )
continue;
// Using the operator= function to initialize all variables..

View File

@ -36,15 +36,15 @@ private:
void check( const char code[] )
{
// Tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.TokenizeCode( istr );
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.TokenizeCode( istr );
tokenizer.SimplifyTokenList();
// Clear the error buffer..
errout.str("");
// Check for memory leaks..
// Check for memory leaks..
CheckClass checkClass( &tokenizer );
checkClass.CheckConstructors();
@ -62,6 +62,7 @@ private:
TEST_CASE( initvar_if ); // BUG 2190290
TEST_CASE( initvar_operator_eq ); // BUG 2190376
TEST_CASE( initvar_same_classname ); // BUG 2208157
TEST_CASE( initvar_chained_assign ); // BUG 2270433
}
@ -202,6 +203,27 @@ private:
ASSERT_EQUALS( std::string(""), err );
}
void initvar_chained_assign()
{
// Bug 2270433 - Uninitialized variable false positive on chained assigns
check( "class c\n"
"{\n"
" c();\n"
"\n"
" int m_iMyInt1;\n"
" int m_iMyInt2;\n"
"}\n"
"\n"
"c::c()\n"
"{\n"
" m_iMyInt1 = m_iMyInt2 = 0;\n"
"}\n" );
std::string err( errout.str() );
ASSERT_EQUALS( std::string(""), err );
}
};