Fixed #1133 (Uninitialized array: strchr, strrchr, etc)

This commit is contained in:
Daniel Marjamäki 2009-12-22 21:07:56 +01:00
parent 566cfce8da
commit 2bd60ab6c8
2 changed files with 9 additions and 2 deletions

View File

@ -1393,13 +1393,13 @@ private:
if (Token::Match(&tok, "%var% ("))
{
// reading 1st parameter..
if (Token::Match(&tok, "strcat|strncat|strlen ( %var%"))
if (Token::Match(&tok, "strcat|strncat|strchr|strrchr|strstr|strlen|strdup ( %var%"))
{
use_array(foundError, checks, tok.tokAt(2));
}
// reading 2nd parameter..
if (Token::Match(&tok, "strcpy ( %any% , %var% ) ") ||
if (Token::Match(&tok, "strcpy|strstr ( %any% , %var% ) ") ||
Token::Match(&tok, "strncpy ( %any% , %var% ,"))
{
use_array(foundError, checks, tok.tokAt(4));

View File

@ -1233,6 +1233,13 @@ private:
"};\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
" char s[20];\n"
" strchr(s, ' ');\n"
"};\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
" char s[20];\n"