Improving 'Wrong assignment of auto variable' error message.

Improving the error message as discussed at dev-forum:
https://sourceforge.net/apps/phpbb/cppcheck/viewtopic.php?f=3&t=192&start=0
This commit is contained in:
Kimmo Varis 2010-12-04 09:55:20 +02:00
parent 758fc85a12
commit 8369d0ddd6
2 changed files with 8 additions and 5 deletions

View File

@ -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
{

View File

@ -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()