errormessage: Added the new errormessage handling to cppcheck

This commit is contained in:
Daniel Marjamäki 2009-01-08 17:32:33 +00:00
parent 1bc5740742
commit 2a2adb037a
3 changed files with 9 additions and 10 deletions

View File

@ -19,6 +19,8 @@
#include "checkmemoryleak.h" #include "checkmemoryleak.h"
#include "errormessage.h"
#include <stdlib.h> // free #include <stdlib.h> // free
#include <algorithm> #include <algorithm>
@ -310,17 +312,11 @@ void CheckMemoryLeakClass::MismatchError(const Token *Tok1, const std::list<cons
void CheckMemoryLeakClass::MemoryLeak(const Token *tok, const char varname[], AllocType alloctype) void CheckMemoryLeakClass::MemoryLeak(const Token *tok, const char varname[], AllocType alloctype)
{ {
std::ostringstream errmsg;
errmsg << _tokenizer->fileLine(tok);
if (alloctype == CheckMemoryLeakClass::FOPEN || if (alloctype == CheckMemoryLeakClass::FOPEN ||
alloctype == CheckMemoryLeakClass::POPEN) alloctype == CheckMemoryLeakClass::POPEN)
errmsg << ": Resource leak: "; _errorLogger->reportErr(ErrorMessage::resourceLeak(_tokenizer, tok, varname));
else else
errmsg << ": Memory leak: "; _errorLogger->reportErr(ErrorMessage::memleak(_tokenizer, tok, varname));
errmsg << varname;
_errorLogger->reportErr(errmsg.str());
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -28,6 +28,8 @@
#include "checkfunctionusage.h" #include "checkfunctionusage.h"
#include "filelister.h" #include "filelister.h"
#include "errormessage.h"
#include <algorithm> #include <algorithm>
#include <sstream> #include <sstream>
#include <cstring> #include <cstring>
@ -271,6 +273,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
// Memory leak // Memory leak
CheckMemoryLeakClass checkMemoryLeak(&_tokenizer, _settings, this); CheckMemoryLeakClass checkMemoryLeak(&_tokenizer, _settings, this);
if ( ErrorMessage::memleak(_settings) )
checkMemoryLeak.CheckMemoryLeak(); checkMemoryLeak.CheckMemoryLeak();
// Check that all class constructors are ok. // Check that all class constructors are ok.

View File

@ -12,9 +12,9 @@ The "simple" tasks
- etc? - etc?
* Add unit tests * Add unit tests
* improved error message handling * improved error message handling
* Perhaps the parseArgs function should be moved to the class Settings instead?
New checks (bugs) New checks (bugs)
* sprintf problem with overlapping data
* CheckMemoryLeak * CheckMemoryLeak
- Check for more resource leaks - Check for more resource leaks
Windows API (CreatePen, GetDC, ..) Windows API (CreatePen, GetDC, ..)