diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 2d44003fb..883b58b84 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -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); diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 383994d20..27328e113 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -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"