Fix #2813 (False negative: Uninitialized variable not found for realloc)

http://sourceforge.net/apps/trac/cppcheck/ticket/2813
Patch provided by: marekzmyslowski
This commit is contained in:
Reijo Tomperi 2011-09-28 21:46:09 +03:00
parent 9994218aa2
commit 236d0eb178
2 changed files with 14 additions and 1 deletions

View File

@ -651,7 +651,8 @@ private:
return tok.next()->link();
// deallocate pointer
if (Token::Match(&tok, "free|kfree|fclose ( %var% )"))
if (Token::Match(&tok, "free|kfree|fclose ( %var% )") ||
Token::Match(&tok, "realloc ( %var%"))
{
dealloc_pointer(checks, tok.tokAt(2));
return tok.tokAt(3);

View File

@ -85,6 +85,18 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
checkUninitVar("void foo() {\n"
" int *p;\n"
" realloc(p,10);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: p\n", errout.str());
checkUninitVar("void foo() {\n"
" int *p = NULL;\n"
" realloc(p,10);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// dereferencing uninitialized pointer..
checkUninitVar("static void foo()\n"
"{\n"