fix ticket 155 - char array

This commit is contained in:
Sébastien Debrard 2011-01-24 19:04:56 +01:00
parent f611c9aec7
commit c7b8bd543f
2 changed files with 11 additions and 3 deletions

View File

@ -95,7 +95,7 @@ void CheckOther::checkSizeofForArrayParameter()
const Token *declTok = Token::findmatch(_tokenizer->tokens(), "%varid%", tok->tokAt(tokIdx)->varId());
if (declTok)
{
if ((Token::simpleMatch(declTok->next(), "[")) && !(Token::simpleMatch(declTok->next()->link(), "] = {")) && !(Token::simpleMatch(declTok->next()->link(), "] ;")))
if ((Token::simpleMatch(declTok->next(), "[")) && !(Token::Match(declTok->next()->link(), "] = %str%")) && !(Token::simpleMatch(declTok->next()->link(), "] = {")) && !(Token::simpleMatch(declTok->next()->link(), "] ;")))
{
sizeofForArrayParameterError(tok);
}

View File

@ -98,7 +98,7 @@ private:
TEST_CASE(memsetZeroBytes);
TEST_CASE(sizeofWithSilentArrayPointer);
TEST_CASE(sizeofForArrayParameter);
}
void check(const char code[], const char *filename = NULL)
@ -1663,7 +1663,7 @@ private:
ASSERT_EQUALS("", errout.str());
}
void sizeofWithSilentArrayPointer()
void sizeofForArrayParameter()
{
check("void f() {\n"
" int a[10];\n"
@ -1742,6 +1742,14 @@ private:
);
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" char p[] = \"test\";\n"
" sizeof(p);\n"
"}\n"
);
ASSERT_EQUALS("", errout.str());
}
};