fix #2931 (another false negative in auto variables checking when function parameter is a struct)
This commit is contained in:
parent
84ca1902a5
commit
527c1aae33
|
@ -112,6 +112,17 @@ void CheckAutoVariables::autoVariables()
|
|||
}
|
||||
tok = tok->tokAt(6);
|
||||
}
|
||||
else if (Token::Match(tok, "[;{}] %var% . %var% = %var% ;"))
|
||||
{
|
||||
const Variable * var1 = symbolDatabase->getVariableFromVarId(tok->tokAt(1)->varId());
|
||||
if (var1 && var1->isArgument() && Token::Match(var1->nameToken()->tokAt(-2), "%type% *"))
|
||||
{
|
||||
const Variable * var2 = symbolDatabase->getVariableFromVarId(tok->tokAt(5)->varId());
|
||||
if (var2 && var2->isLocal() && var2->isArray() && !var2->isStatic())
|
||||
errorAutoVariableAssignment(tok);
|
||||
}
|
||||
tok = tok->tokAt(5);
|
||||
}
|
||||
else if (Token::Match(tok, "[;{}] * %var% = %var% ;"))
|
||||
{
|
||||
const Variable * var1 = symbolDatabase->getVariableFromVarId(tok->tokAt(2)->varId());
|
||||
|
|
|
@ -73,6 +73,7 @@ private:
|
|||
TEST_CASE(testautovar4); // ticket #2928
|
||||
TEST_CASE(testautovar5); // ticket #2926
|
||||
TEST_CASE(testautovar6); // ticket #1514
|
||||
TEST_CASE(testautovar7); // ticket #2931
|
||||
TEST_CASE(testautovar_array1);
|
||||
TEST_CASE(testautovar_array2);
|
||||
TEST_CASE(testautovar_return1);
|
||||
|
@ -197,6 +198,16 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:3]: (error) Assigning address of local auto-variable to a function parameter.\n", errout.str());
|
||||
}
|
||||
|
||||
void testautovar7() // ticket #2931
|
||||
{
|
||||
check("void foo(struct X *x)\n"
|
||||
"{\n"
|
||||
" char a[10];\n"
|
||||
" x->str = a;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Assigning address of local auto-variable to a function parameter.\n", errout.str());
|
||||
}
|
||||
|
||||
void testautovar_array1()
|
||||
{
|
||||
check("void func1(int* arr[2])\n"
|
||||
|
|
Loading…
Reference in New Issue