From 31e3844f3f328d2d13cf3fb41a802a93fa1df604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 21 Jul 2011 14:50:38 +0200 Subject: [PATCH] Fixed #2856 (--errorlist not printing all auto-variable errors) --- lib/checkautovariables.cpp | 15 +++++++++++++-- lib/checkautovariables.h | 4 ++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 164a94195..5c040d424 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -119,12 +119,12 @@ void CheckAutoVariables::autoVariables() // Critical return 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 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) { 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"); } +void CheckAutoVariables::errorInvalidDeallocation(const Token *tok) +{ + reportError(tok, Severity::error, "autovarInvalidDeallocation", "Invalid deallocation"); +} + + //--------------------------------------------------------------------------- // Return c_str diff --git a/lib/checkautovariables.h b/lib/checkautovariables.h index 45c01f5a8..43d9c166c 100644 --- a/lib/checkautovariables.h +++ b/lib/checkautovariables.h @@ -81,22 +81,26 @@ private: */ bool returnTemporary(const Token *tok) const; + void errorReturnAddressToAutoVariable(const Token *tok); void errorReturnPointerToLocalArray(const Token *tok); void errorAutoVariableAssignment(const Token *tok); void errorReturnReference(const Token *tok); void errorReturnTempReference(const Token *tok); void errorReturnAutocstr(const Token *tok); void errorReturnTempPointer(const Token *tok); + void errorInvalidDeallocation(const Token *tok); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { CheckAutoVariables c(0,settings,errorLogger); c.errorAutoVariableAssignment(0); + c.errorReturnAddressToAutoVariable(0); c.errorReturnPointerToLocalArray(0); c.errorReturnReference(0); c.errorReturnTempReference(0); c.errorReturnAutocstr(0); c.errorReturnTempPointer(0); + c.errorInvalidDeallocation(0); } std::string myName() const