Ticket #6596: Address of local variables can also be assigned to pointer-pointer arguments using the ptr[] syntax.

This commit is contained in:
Simon Martin 2015-08-28 20:29:51 +02:00
parent 498c920180
commit 59abb04042
2 changed files with 11 additions and 1 deletions

View File

@ -190,7 +190,8 @@ void CheckAutoVariables::autoVariables()
errorAutoVariableAssignment(tok->next(), false);
}
tok = tok->tokAt(4);
} else if (Token::Match(tok, "[;{}] %var% [") && Token::Match(tok->linkAt(2), "] = & %var%") && isArrayArg(tok->next()) && isAutoVar(tok->linkAt(2)->tokAt(3))) {
} else if (Token::Match(tok, "[;{}] %var% [") && Token::Match(tok->linkAt(2), "] = & %var%") &&
(isPtrArg(tok->next()) || isArrayArg(tok->next())) && isAutoVar(tok->linkAt(2)->tokAt(3))) {
const Token* const varTok = tok->linkAt(2)->tokAt(3);
if (checkRvalueExpression(varTok))
errorAutoVariableAssignment(tok->next(), false);

View File

@ -75,6 +75,7 @@ private:
TEST_CASE(testautovar15); // ticket #6538
TEST_CASE(testautovar_array1);
TEST_CASE(testautovar_array2);
TEST_CASE(testautovar_ptrptr); // ticket #6956
TEST_CASE(testautovar_return1);
TEST_CASE(testautovar_return2);
TEST_CASE(testautovar_return3);
@ -424,6 +425,14 @@ private:
ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
}
void testautovar_ptrptr() { // #6596
check("void remove_duplicate_matches (char **matches) {\n"
" char dead_slot;\n"
" matches[0] = (char *)&dead_slot;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
}
void testautovar_return1() {
check("int* func1()\n"
"{\n"