Merge branch 'master' of git@github.com:danmar/cppcheck

This commit is contained in:
Reijo Tomperi 2009-08-04 22:42:01 +03:00
commit 35f9bc3009
11 changed files with 50 additions and 37 deletions

View File

@ -87,6 +87,7 @@ protected:
void reportError(const Token *tok, const Severity::e severity, const std::string &id, const std::string &msg) void reportError(const Token *tok, const Severity::e severity, const std::string &id, const std::string &msg)
{ {
std::list<const Token *> callstack; std::list<const Token *> callstack;
if (tok)
callstack.push_back(tok); callstack.push_back(tok);
reportError(callstack, severity, id, msg); reportError(callstack, severity, id, msg);
} }
@ -94,13 +95,6 @@ protected:
/** report an error */ /** report an error */
void reportError(const std::list<const Token *> &callstack, const Severity::e severity, const std::string &id, std::string msg) void reportError(const std::list<const Token *> &callstack, const Severity::e severity, const std::string &id, std::string msg)
{ {
// No errorLogger => just report the message to stdout
if (_errorLogger == NULL)
{
std::cout << "(" << Severity::stringify(severity) << ") " << msg << std::endl;
return;
}
// If the verbose flag hasn't been given, don't show verbose information // If the verbose flag hasn't been given, don't show verbose information
if (!_settings || !_settings->_verbose) if (!_settings || !_settings->_verbose)
{ {
@ -118,7 +112,12 @@ protected:
locationList.push_back(loc); locationList.push_back(loc);
} }
_errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList, Severity::stringify(severity), msg, id)); const ErrorLogger::ErrorMessage errmsg(locationList, Severity::stringify(severity), msg, id);
if (_errorLogger)
_errorLogger->reportErr(errmsg);
else
std::cout << errmsg.toXML() << std::endl;
} }
private: private:

View File

@ -70,7 +70,6 @@ private:
void getErrorMessages() void getErrorMessages()
{ {
std::cout << "===auto variables===" << "\n";
reportError(0, Severity::error, "autoVariables", "Wrong assignement of an auto-variable to an effective parameter of a function"); reportError(0, Severity::error, "autoVariables", "Wrong assignement of an auto-variable to an effective parameter of a function");
errorReturnPointerToLocalArray(0); errorReturnPointerToLocalArray(0);
} }

View File

@ -45,11 +45,16 @@ CheckBufferOverrun instance;
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckBufferOverrun::arrayIndexOutOfBounds(const Token *tok) void CheckBufferOverrun::arrayIndexOutOfBounds(const Token *tok)
{
if (!tok)
arrayIndexOutOfBounds();
else
{ {
_callStack.push_back(tok); _callStack.push_back(tok);
arrayIndexOutOfBounds(); arrayIndexOutOfBounds();
_callStack.pop_back(); _callStack.pop_back();
} }
}
void CheckBufferOverrun::arrayIndexOutOfBounds() void CheckBufferOverrun::arrayIndexOutOfBounds()
{ {

View File

@ -79,7 +79,6 @@ private:
void getErrorMessages() void getErrorMessages()
{ {
std::cout << "===buffer overruns===" << "\n";
arrayIndexOutOfBounds(0); arrayIndexOutOfBounds(0);
bufferOverrun(0); bufferOverrun(0);
strncatUsage(0); strncatUsage(0);

View File

@ -114,7 +114,6 @@ private:
void getErrorMessages() void getErrorMessages()
{ {
std::cout << "===classes===" << "\n";
noConstructorError(0, "classname"); noConstructorError(0, "classname");
uninitVarError(0, "classname", "varname"); uninitVarError(0, "classname", "varname");
operatorEqVarError(0, "classname", ""); operatorEqVarError(0, "classname", "");

View File

@ -59,7 +59,6 @@ private:
void getErrorMessages() void getErrorMessages()
{ {
std::cout << "===dangerous functions===" << "\n";
dangerousFunctionmktemp(0); dangerousFunctionmktemp(0);
dangerousFunctiongets(0); dangerousFunctiongets(0);
dangerousFunctionscanf(0); dangerousFunctionscanf(0);

View File

@ -224,19 +224,17 @@ void CheckMemoryLeak::memoryLeak(const Token *tok, const char varname[], AllocTy
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
ErrorLogger::ErrorMessage CheckMemoryLeak::errmsg(const Token *tok, Severity::e severity, const std::string &id, const std::string &msg) const void CheckMemoryLeak::reportErr(const Token *tok, Severity::e severity, const std::string &id, const std::string &msg) const
{ {
ErrorLogger::ErrorMessage::FileLocation loc; std::list<const Token *> callstack;
loc.line = tok->linenr();
loc.file = tokenizer->file(tok);
std::list<ErrorLogger::ErrorMessage::FileLocation> callstack; if (tok)
callstack.push_back(loc); callstack.push_back(tok);
return ErrorLogger::ErrorMessage(callstack, Severity::stringify(severity), msg, id); reportErr(callstack, severity, id, msg);
} }
ErrorLogger::ErrorMessage CheckMemoryLeak::errmsg(const std::list<const Token *> &callstack, Severity::e severity, const std::string &id, const std::string &msg) const void CheckMemoryLeak::reportErr(const std::list<const Token *> &callstack, Severity::e severity, const std::string &id, const std::string &msg) const
{ {
std::list<ErrorLogger::ErrorMessage::FileLocation> locations; std::list<ErrorLogger::ErrorMessage::FileLocation> locations;
@ -249,42 +247,47 @@ ErrorLogger::ErrorMessage CheckMemoryLeak::errmsg(const std::list<const Token *>
locations.push_back(loc); locations.push_back(loc);
} }
return ErrorLogger::ErrorMessage(locations, Severity::stringify(severity), msg, id); const ErrorLogger::ErrorMessage errmsg(locations, Severity::stringify(severity), msg, id);
if (errorLogger)
errorLogger->reportErr(errmsg);
else
std::cout << errmsg.toXML() << std::endl;
} }
void CheckMemoryLeak::memleakError(const Token *tok, const std::string &varname) void CheckMemoryLeak::memleakError(const Token *tok, const std::string &varname)
{ {
errorLogger->reportErr(errmsg(tok, Severity::error, "memleak", "Memory leak: " + varname)); reportErr(tok, Severity::error, "memleak", "Memory leak: " + varname);
} }
void CheckMemoryLeak::memleakallError(const Token *tok, const std::string &varname) void CheckMemoryLeak::memleakallError(const Token *tok, const std::string &varname)
{ {
errorLogger->reportErr(errmsg(tok, Severity::possibleError, "memleakall", "Memory leak: " + varname)); reportErr(tok, Severity::possibleError, "memleakall", "Memory leak: " + varname);
} }
void CheckMemoryLeak::resourceLeakError(const Token *tok, const std::string &varname) void CheckMemoryLeak::resourceLeakError(const Token *tok, const std::string &varname)
{ {
errorLogger->reportErr(errmsg(tok, Severity::error, "resourceLeak", "Resource leak: " + varname)); reportErr(tok, Severity::error, "resourceLeak", "Resource leak: " + varname);
} }
void CheckMemoryLeak::deallocDeallocError(const Token *tok, const std::string &varname) void CheckMemoryLeak::deallocDeallocError(const Token *tok, const std::string &varname)
{ {
errorLogger->reportErr(errmsg(tok, Severity::error, "deallocDealloc", "Deallocating a deallocated pointer: " + varname)); reportErr(tok, Severity::error, "deallocDealloc", "Deallocating a deallocated pointer: " + varname);
} }
void CheckMemoryLeak::deallocuseError(const Token *tok, const std::string &varname) void CheckMemoryLeak::deallocuseError(const Token *tok, const std::string &varname)
{ {
errorLogger->reportErr(errmsg(tok, Severity::error, "deallocuse", "Dereferencing '" + varname + "' after it is deallocated / released")); reportErr(tok, Severity::error, "deallocuse", "Dereferencing '" + varname + "' after it is deallocated / released");
} }
void CheckMemoryLeak::mismatchSizeError(const Token *tok, const std::string &sz) void CheckMemoryLeak::mismatchSizeError(const Token *tok, const std::string &sz)
{ {
errorLogger->reportErr(errmsg(tok, Severity::error, "mismatchSize", "The given size " + sz + " is mismatching")); reportErr(tok, Severity::error, "mismatchSize", "The given size " + sz + " is mismatching");
} }
void CheckMemoryLeak::mismatchAllocDealloc(const std::list<const Token *> &callstack, const std::string &varname) void CheckMemoryLeak::mismatchAllocDealloc(const std::list<const Token *> &callstack, const std::string &varname)
{ {
errorLogger->reportErr(errmsg(callstack, Severity::error, "mismatchAllocDealloc", "Mismatching allocation and deallocation: " + varname)); reportErr(callstack, Severity::error, "mismatchAllocDealloc", "Mismatching allocation and deallocation: " + varname);
} }
CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Token *tok) const CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Token *tok) const

View File

@ -63,7 +63,7 @@ private:
* @param id type of message * @param id type of message
* @param msg text * @param msg text
*/ */
ErrorLogger::ErrorMessage errmsg(const Token *location, Severity::e severity, const std::string &id, const std::string &msg) const; void reportErr(const Token *location, Severity::e severity, const std::string &id, const std::string &msg) const;
/** /**
* Report error. Similar with the function Check::reportError * Report error. Similar with the function Check::reportError
@ -72,7 +72,7 @@ private:
* @param id type of message * @param id type of message
* @param msg text * @param msg text
*/ */
ErrorLogger::ErrorMessage errmsg(const std::list<const Token *> &callstack, Severity::e severity, const std::string &id, const std::string &msg) const; void reportErr(const std::list<const Token *> &callstack, Severity::e severity, const std::string &id, const std::string &msg) const;
public: public:
CheckMemoryLeak(const Tokenizer *t, ErrorLogger *e) CheckMemoryLeak(const Tokenizer *t, ErrorLogger *e)
@ -233,7 +233,17 @@ private:
void checkScope(const Token *Tok1, const char varname[], bool classmember, unsigned int sz); void checkScope(const Token *Tok1, const char varname[], bool classmember, unsigned int sz);
void getErrorMessages() void getErrorMessages()
{ } {
memleakError(0, "varname");
memleakallError(0, "varname");
resourceLeakError(0, "varname");
deallocDeallocError(0, "varname");
deallocuseError(0, "varname");
mismatchSizeError(0, "sz");
std::list<const Token *> callstack;
mismatchAllocDealloc(callstack, "varname");
}
std::string name() const std::string name() const
{ {

View File

@ -148,7 +148,6 @@ public:
void getErrorMessages() void getErrorMessages()
{ {
std::cout << "===other===" << "\n";
cstyleCastError(0); cstyleCastError(0);
redundantIfDelete0Error(0); redundantIfDelete0Error(0);
redundantIfRemoveError(0); redundantIfRemoveError(0);

View File

@ -103,7 +103,6 @@ private:
void getErrorMessages() void getErrorMessages()
{ {
std::cout << "===stl===" << "\n";
iteratorsError(0, "container1", "container2"); iteratorsError(0, "container1", "container2");
dereferenceErasedError(0, "iter"); dereferenceErasedError(0, "iter");
stlOutOfBoundsError(0, "i", "foo"); stlOutOfBoundsError(0, "i", "foo");

View File

@ -223,10 +223,12 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
else if (strcmp(argv[i], "--errorlist") == 0) else if (strcmp(argv[i], "--errorlist") == 0)
{ {
// call all "getErrorMessages" in all registered Check classes // call all "getErrorMessages" in all registered Check classes
std::cout << ErrorLogger::ErrorMessage::getXMLHeader();
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
{ {
(*it)->getErrorMessages(); (*it)->getErrorMessages();
} }
std::cout << ErrorLogger::ErrorMessage::getXMLFooter() << std::endl;
return ""; return "";
} }