Fixed #2856 (--errorlist not printing all auto-variable errors)

This commit is contained in:
Daniel Marjamäki 2011-07-21 14:50:38 +02:00
parent d1d8c24a03
commit 31e3844f3f
2 changed files with 17 additions and 2 deletions

View File

@ -119,12 +119,12 @@ void CheckAutoVariables::autoVariables()
// 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()))
{ {
reportError(tok, Severity::error, "autoVariables", "Return of the address of an auto-variable"); errorReturnAddressToAutoVariable(tok);
} }
// Invalid pointer deallocation // Invalid pointer deallocation
else if (Token::Match(tok, "free ( %var% ) ;") && isAutoVarArray(tok->tokAt(2)->varId())) else if (Token::Match(tok, "free ( %var% ) ;") && isAutoVarArray(tok->tokAt(2)->varId()))
{ {
reportError(tok, Severity::error, "autoVariables", "Invalid deallocation"); errorInvalidDeallocation(tok);
} }
} }
} }
@ -188,6 +188,11 @@ void CheckAutoVariables::returnPointerToLocalArray()
} }
} }
void CheckAutoVariables::errorReturnAddressToAutoVariable(const Token *tok)
{
reportError(tok, Severity::error, "returnAddressOfAutoVariable", "Return of the address of an auto-variable");
}
void CheckAutoVariables::errorReturnPointerToLocalArray(const Token *tok) 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");
@ -291,6 +296,12 @@ void CheckAutoVariables::errorReturnTempReference(const Token *tok)
reportError(tok, Severity::error, "returnTempReference", "Returning reference to temporary"); reportError(tok, Severity::error, "returnTempReference", "Returning reference to temporary");
} }
void CheckAutoVariables::errorInvalidDeallocation(const Token *tok)
{
reportError(tok, Severity::error, "autovarInvalidDeallocation", "Invalid deallocation");
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Return c_str // Return c_str

View File

@ -81,22 +81,26 @@ private:
*/ */
bool returnTemporary(const Token *tok) const; bool returnTemporary(const Token *tok) const;
void errorReturnAddressToAutoVariable(const Token *tok);
void errorReturnPointerToLocalArray(const Token *tok); void errorReturnPointerToLocalArray(const Token *tok);
void errorAutoVariableAssignment(const Token *tok); void errorAutoVariableAssignment(const Token *tok);
void errorReturnReference(const Token *tok); void errorReturnReference(const Token *tok);
void errorReturnTempReference(const Token *tok); void errorReturnTempReference(const Token *tok);
void errorReturnAutocstr(const Token *tok); void errorReturnAutocstr(const Token *tok);
void errorReturnTempPointer(const Token *tok); void errorReturnTempPointer(const Token *tok);
void errorInvalidDeallocation(const Token *tok);
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
{ {
CheckAutoVariables c(0,settings,errorLogger); CheckAutoVariables c(0,settings,errorLogger);
c.errorAutoVariableAssignment(0); c.errorAutoVariableAssignment(0);
c.errorReturnAddressToAutoVariable(0);
c.errorReturnPointerToLocalArray(0); c.errorReturnPointerToLocalArray(0);
c.errorReturnReference(0); c.errorReturnReference(0);
c.errorReturnTempReference(0); c.errorReturnTempReference(0);
c.errorReturnAutocstr(0); c.errorReturnAutocstr(0);
c.errorReturnTempPointer(0); c.errorReturnTempPointer(0);
c.errorInvalidDeallocation(0);
} }
std::string myName() const std::string myName() const