Uninitialized variables: Passing uninitialized array as parameter to function. Ticket: #2188
This commit is contained in:
parent
e523d5a3a3
commit
9d7a623985
|
@ -456,6 +456,14 @@ private:
|
|||
|
||||
if (tok.varId())
|
||||
{
|
||||
// array variable passed as function parameter..
|
||||
if (Token::Match(tok.previous(), "[(,] %var% [+-,)]"))
|
||||
{
|
||||
use(checks, &tok);
|
||||
use_array(checks, &tok);
|
||||
return &tok;
|
||||
}
|
||||
|
||||
// Used..
|
||||
if (Token::Match(tok.previous(), "[[(,+-*/] %var% []),+-*/]"))
|
||||
{
|
||||
|
|
|
@ -1131,7 +1131,7 @@ private:
|
|||
ASSERT_EQUALS("foo", analyseFunctions("void foo(int x);"));
|
||||
ASSERT_EQUALS("foo", analyseFunctions("void foo(const int &x) { }"));
|
||||
ASSERT_EQUALS("foo", analyseFunctions("void foo(int &x) { ++x; }"));
|
||||
ASSERT_EQUALS("rename", analyseFunctions("int rename (const char* oldname, const char* newname);"));
|
||||
ASSERT_EQUALS("rename", analyseFunctions("int rename (const char* oldname, const char* newname);")); // Ticket #914
|
||||
ASSERT_EQUALS("rename", analyseFunctions("int rename (const char oldname[], const char newname[]);"));
|
||||
ASSERT_EQUALS("", analyseFunctions("void foo(int &x) { x = 0; }"));
|
||||
ASSERT_EQUALS("", analyseFunctions("void foo(s x) { }"));
|
||||
|
@ -1213,6 +1213,13 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar("int calc(const int *p, int n);\n"
|
||||
"void f() {\n"
|
||||
" int x[10];\n"
|
||||
" calc(x,10);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout.str());
|
||||
|
||||
// using uninitialized function pointer..
|
||||
checkUninitVar("void foo()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue