Fixed #783 (Refactoring: autoVariables error message is hard coded in 3 locations)

http://sourceforge.net/apps/trac/cppcheck/ticket/783
This commit is contained in:
Slava Semushin 2009-10-04 16:45:45 +07:00
parent 29e7261529
commit 3c5b13a276
2 changed files with 8 additions and 10 deletions

View File

@ -196,18 +196,12 @@ void CheckAutoVariables::autoVariables()
//Critical assignement //Critical assignement
else if (Token::Match(tok, "[;{}] %var% = & %var%") && errorAv(tok->tokAt(1), tok->tokAt(4))) else if (Token::Match(tok, "[;{}] %var% = & %var%") && errorAv(tok->tokAt(1), tok->tokAt(4)))
{ {
reportError(tok, errorAutoVariableAssignment(tok);
Severity::error,
"autoVariables",
"Wrong assignement of an auto-variable to an effective parameter of a function");
} }
//Critical assignement //Critical assignement
else if (Token::Match(tok, "[;{}] %var% [ %any% ] = & %var%") && errorAv(tok->tokAt(1), tok->tokAt(7))) else if (Token::Match(tok, "[;{}] %var% [ %any% ] = & %var%") && errorAv(tok->tokAt(1), tok->tokAt(7)))
{ {
reportError(tok, errorAutoVariableAssignment(tok);
Severity::error,
"autoVariables",
"Wrong assignement of an auto-variable to an effective parameter of a function");
} }
// Critical return // Critical return
else if (Token::Match(tok, "return & %var% ;") && isAutoVar(tok->tokAt(2)->varId())) else if (Token::Match(tok, "return & %var% ;") && isAutoVar(tok->tokAt(2)->varId()))
@ -304,5 +298,8 @@ void CheckAutoVariables::errorReturnPointerToLocalArray(const Token *tok)
reportError(tok, Severity::error, "returnLocalVariable", "Returning pointer to local array variable"); reportError(tok, Severity::error, "returnLocalVariable", "Returning pointer to local array variable");
} }
void CheckAutoVariables::errorAutoVariableAssignment(const Token *tok)
{
reportError(tok, Severity::error, "autoVariables", "Wrong assignement of an auto-variable to an effective parameter of a function");
}

View File

@ -69,11 +69,12 @@ private:
void errorReturnPointerToLocalArray(const Token *tok); void errorReturnPointerToLocalArray(const Token *tok);
void errorAutoVariableAssignment(const Token *tok);
void getErrorMessages() void getErrorMessages()
{ {
reportError(0, Severity::error, "autoVariables", "Wrong assignement of an auto-variable to an effective parameter of a function"); errorAutoVariableAssignment(0);
errorReturnPointerToLocalArray(0); errorReturnPointerToLocalArray(0);
} }