Merge branch 'master' of http://github.com/danmar/cppcheck
This commit is contained in:
commit
148429ef6e
|
@ -149,9 +149,38 @@ void CheckOther::checkSizeofForArrayParameter()
|
|||
const Token *declTok = Token::findmatch(_tokenizer->tokens(), "%varid%", tok->tokAt(tokIdx)->varId());
|
||||
if (declTok)
|
||||
{
|
||||
if ((Token::simpleMatch(declTok->next(), "[")) && !(Token::Match(declTok->next()->link(), "] = %str%")) && !(Token::simpleMatch(declTok->next()->link(), "] = {")) && !(Token::simpleMatch(declTok->next()->link(), "] ;")))
|
||||
if (Token::simpleMatch(declTok->next(), "["))
|
||||
{
|
||||
declTok = declTok->next()->link();
|
||||
// multidimensional array
|
||||
while (Token::simpleMatch(declTok->next(), "["))
|
||||
{
|
||||
declTok = declTok->next()->link();
|
||||
}
|
||||
if (!(Token::Match(declTok->next(), "= %str%")) && !(Token::simpleMatch(declTok->next(), "= {")) && !(Token::simpleMatch(declTok->next(), ";")))
|
||||
{
|
||||
if (Token::simpleMatch(declTok->next(), ","))
|
||||
{
|
||||
declTok = declTok->next();
|
||||
while (!Token::simpleMatch(declTok, ";"))
|
||||
{
|
||||
if (Token::simpleMatch(declTok, ")"))
|
||||
{
|
||||
sizeofForArrayParameterError(tok);
|
||||
break;
|
||||
}
|
||||
if (Token::Match(declTok, "(|[|{"))
|
||||
{
|
||||
declTok = declTok->link();
|
||||
}
|
||||
declTok = declTok->next();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Token::simpleMatch(declTok->next(), ")"))
|
||||
{
|
||||
sizeofForArrayParameterError(tok);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1751,6 +1751,54 @@ private:
|
|||
"}\n"
|
||||
);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// ticket 2495
|
||||
check("void f() {\n"
|
||||
" static float col[][3]={\n"
|
||||
" {1,0,0},\n"
|
||||
" {0,0,1},\n"
|
||||
" {0,1,0},\n"
|
||||
" {1,0,1},\n"
|
||||
" {1,0,1},\n"
|
||||
" {1,0,1},\n"
|
||||
" };\n"
|
||||
" const int COL_MAX=sizeof(col)/sizeof(col[0]);\n"
|
||||
"}\n"
|
||||
);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// ticket 155
|
||||
check("void f() {\n"
|
||||
" char buff1[1024*64],buff2[sizeof(buff1)*2];\n"
|
||||
"}\n"
|
||||
);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// ticket 2510
|
||||
check("void f( int a[], int b) {\n"
|
||||
" std::cout << sizeof(a) / sizeof(int) << std::endl;\n"
|
||||
"}\n"
|
||||
);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (error) Using sizeof for array given as "
|
||||
"function argument returns the size of pointer.\n", errout.str());
|
||||
|
||||
// ticket 2510
|
||||
check("void f( int a[3] , int b[2] ) {\n"
|
||||
" std::cout << sizeof(a) / sizeof(int) << std::endl;\n"
|
||||
"}\n"
|
||||
);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (error) Using sizeof for array given as "
|
||||
"function argument returns the size of pointer.\n", errout.str());
|
||||
|
||||
// ticket 2510
|
||||
check("void f() {\n"
|
||||
" char buff1[1024*64],buff2[sizeof(buff1)*(2+1)];\n"
|
||||
"}\n"
|
||||
);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void clarifyCalculation()
|
||||
|
|
Loading…
Reference in New Issue