Fix 2495 incorrect sizeof error message

This commit is contained in:
Sébastien Debrard 2011-01-25 09:57:58 +01:00
parent c7b8bd543f
commit 4cf56dac2b
2 changed files with 27 additions and 2 deletions

View File

@ -95,7 +95,15 @@ void CheckOther::checkSizeofForArrayParameter()
const Token *declTok = Token::findmatch(_tokenizer->tokens(), "%varid%", tok->tokAt(tokIdx)->varId()); const Token *declTok = Token::findmatch(_tokenizer->tokens(), "%varid%", tok->tokAt(tokIdx)->varId());
if (declTok) 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(), ";")) && !(Token::simpleMatch(declTok->next(), ",")))
{ {
sizeofForArrayParameterError(tok); sizeofForArrayParameterError(tok);
} }
@ -103,6 +111,7 @@ void CheckOther::checkSizeofForArrayParameter()
} }
} }
} }
}
} }

View File

@ -1749,6 +1749,22 @@ private:
); );
ASSERT_EQUALS("", errout.str()); 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());
} }