diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 1bf5a76e5..b1f1e33f9 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -313,11 +313,14 @@ void CheckAutoVariables::errorReturnPointerToLocalArray(const Token *tok) void CheckAutoVariables::errorAutoVariableAssignment(const Token *tok) { - reportError(tok, Severity::error, "autoVariables", "Wrong assignment of an auto-variable to an effective parameter of a function"); + reportError(tok, Severity::error, "autoVariables", + "Assigning address of local auto-variable to a function parameter.\n" + "Dangerous assignment - function parameter takes the address of a local " + "auto-variable. Local auto-variables are reserved from the stack. And the " + "stack is freed when the function ends. So the pointer to a local variable " + "is invalid after the function ends."); } - - // return temporary? bool CheckAutoVariables::returnTemporary(const Token *tok) const { diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index c721d685c..ba11a7d9c 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -91,7 +91,7 @@ private: " int num = 2;\n" " *res = #\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Wrong assignment of an auto-variable to an effective parameter of a function\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Assigning address of local auto-variable to a function parameter.\n", errout.str()); check("void func1(int **res)\n" "{\n" @@ -108,7 +108,7 @@ private: " int num=2;" " arr[0]=#\n" "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Wrong assignment of an auto-variable to an effective parameter of a function\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Assigning address of local auto-variable to a function parameter.\n", errout.str()); } void testautovar_return()