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:
parent
9994218aa2
commit
236d0eb178
|
@ -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);
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue