refactoring the rest of the classes
This commit is contained in:
parent
21dff96e7b
commit
9f1c3cc535
|
@ -36,6 +36,13 @@
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Register this check class (by creating a static instance of it)
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
CheckBufferOverrunClass instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
void CheckBufferOverrunClass::arrayIndexOutOfBounds(const Token *tok)
|
void CheckBufferOverrunClass::arrayIndexOutOfBounds(const Token *tok)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
|
|
||||||
#include "checkdangerousfunctions.h"
|
#include "checkdangerousfunctions.h"
|
||||||
|
|
||||||
|
#include "tokenize.h"
|
||||||
|
#include "token.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
@ -33,19 +36,11 @@
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
// _callStack used when parsing into subfunctions.
|
|
||||||
|
|
||||||
|
// Register this check class (by creating a static instance of it)
|
||||||
CheckDangerousFunctionsClass::CheckDangerousFunctionsClass(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger)
|
namespace
|
||||||
: _settings(settings)
|
|
||||||
{
|
{
|
||||||
_tokenizer = tokenizer;
|
CheckDangerousFunctionsClass instance;
|
||||||
_errorLogger = errorLogger;
|
|
||||||
}
|
|
||||||
|
|
||||||
CheckDangerousFunctionsClass::~CheckDangerousFunctionsClass()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
|
@ -23,23 +23,26 @@
|
||||||
#define CheckDangerousFunctionsH
|
#define CheckDangerousFunctionsH
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "tokenize.h"
|
#include "check.h"
|
||||||
#include "errorlogger.h"
|
|
||||||
|
|
||||||
class CheckDangerousFunctionsClass
|
class CheckDangerousFunctionsClass : public Check
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CheckDangerousFunctionsClass(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger);
|
CheckDangerousFunctionsClass() : Check()
|
||||||
~CheckDangerousFunctionsClass();
|
{ }
|
||||||
|
|
||||||
|
CheckDangerousFunctionsClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
|
: Check(tokenizer, settings, errorLogger)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
|
{
|
||||||
|
CheckDangerousFunctionsClass checkDangerousFunctionsClass(tokenizer, settings, errorLogger);
|
||||||
|
checkDangerousFunctionsClass.dangerousFunctions();
|
||||||
|
}
|
||||||
|
|
||||||
/** Check for buffer overruns */
|
/** Check for buffer overruns */
|
||||||
void dangerousFunctions();
|
void dangerousFunctions();
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
const Tokenizer *_tokenizer;
|
|
||||||
const Settings _settings;
|
|
||||||
ErrorLogger *_errorLogger;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
#include "checkmemoryleak.h"
|
#include "checkmemoryleak.h"
|
||||||
|
|
||||||
|
#include "tokenize.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -27,17 +29,13 @@
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
CheckMemoryLeakClass::CheckMemoryLeakClass(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger)
|
// Register this check class (by creating a static instance of it)
|
||||||
: _settings(settings)
|
namespace
|
||||||
{
|
{
|
||||||
_tokenizer = tokenizer;
|
CheckMemoryLeakClass instance;
|
||||||
_errorLogger = errorLogger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckMemoryLeakClass::~CheckMemoryLeakClass()
|
//---------------------------------------------------------------------------
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CheckMemoryLeakClass::isclass(const Token *tok)
|
bool CheckMemoryLeakClass::isclass(const Token *tok)
|
||||||
{
|
{
|
||||||
|
@ -260,7 +258,7 @@ const char * CheckMemoryLeakClass::call_func(const Token *tok, std::list<const T
|
||||||
--parlevel;
|
--parlevel;
|
||||||
if (parlevel < 1)
|
if (parlevel < 1)
|
||||||
{
|
{
|
||||||
return _settings._showAll ? 0 : "callfunc";
|
return _settings->_showAll ? 0 : "callfunc";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,10 +423,10 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
|
||||||
{
|
{
|
||||||
if (isclass(tok->tokAt(3)))
|
if (isclass(tok->tokAt(3)))
|
||||||
{
|
{
|
||||||
if (_settings._showAll)
|
if (_settings->_showAll)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (_settings.isAutoDealloc(tok->strAt(3)))
|
if (_settings->isAutoDealloc(tok->strAt(3)))
|
||||||
{
|
{
|
||||||
// This class has automatic deallocation
|
// This class has automatic deallocation
|
||||||
alloc = No;
|
alloc = No;
|
||||||
|
@ -800,7 +798,7 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Two "if alloc ;" after one another.. perhaps only one of them can be executed each time
|
// Two "if alloc ;" after one another.. perhaps only one of them can be executed each time
|
||||||
else if (!_settings._showAll && Token::Match(tok2, "[;{}] if alloc ; if alloc ;"))
|
else if (!_settings->_showAll && Token::Match(tok2, "[;{}] if alloc ; if alloc ;"))
|
||||||
{
|
{
|
||||||
erase(tok2, tok2->tokAt(4));
|
erase(tok2, tok2->tokAt(4));
|
||||||
done = false;
|
done = false;
|
||||||
|
@ -820,7 +818,7 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
|
||||||
// Otherwise, only the "if" will be deleted
|
// Otherwise, only the "if" will be deleted
|
||||||
else if (Token::Match(tok2, "[;{}] if assign|dealloc|use ; !!else"))
|
else if (Token::Match(tok2, "[;{}] if assign|dealloc|use ; !!else"))
|
||||||
{
|
{
|
||||||
if (_settings._showAll)
|
if (_settings->_showAll)
|
||||||
{
|
{
|
||||||
erase(tok2, tok2->tokAt(3));
|
erase(tok2, tok2->tokAt(3));
|
||||||
all = true;
|
all = true;
|
||||||
|
@ -890,7 +888,7 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reducing if..
|
// Reducing if..
|
||||||
else if (_settings._showAll)
|
else if (_settings->_showAll)
|
||||||
{
|
{
|
||||||
if (Token::Match(tok2, "[;{}] if { assign|dealloc|use ; return ; } !!else"))
|
if (Token::Match(tok2, "[;{}] if { assign|dealloc|use ; return ; } !!else"))
|
||||||
{
|
{
|
||||||
|
@ -960,7 +958,7 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the "if break|continue ;" that follows "dealloc ; alloc ;"
|
// Remove the "if break|continue ;" that follows "dealloc ; alloc ;"
|
||||||
if (! _settings._showAll && Token::Match(tok2, "dealloc ; alloc ; if break|continue ;"))
|
if (! _settings->_showAll && Token::Match(tok2, "dealloc ; alloc ; if break|continue ;"))
|
||||||
{
|
{
|
||||||
tok2 = tok2->next()->next()->next();
|
tok2 = tok2->next()->next()->next();
|
||||||
erase(tok2, tok2->tokAt(3));
|
erase(tok2, tok2->tokAt(3));
|
||||||
|
@ -1267,7 +1265,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope(const Token *Tok1, const c
|
||||||
MemoryLeak(result->tokAt(3), varname, alloctype, all);
|
MemoryLeak(result->tokAt(3), varname, alloctype, all);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (_settings._showAll && (result = Token::findmatch(tok, "alloc ; ifv break|continue|return ;")) != NULL)
|
else if (_settings->_showAll && (result = Token::findmatch(tok, "alloc ; ifv break|continue|return ;")) != NULL)
|
||||||
{
|
{
|
||||||
MemoryLeak(result->tokAt(3), varname, alloctype, all);
|
MemoryLeak(result->tokAt(3), varname, alloctype, all);
|
||||||
}
|
}
|
||||||
|
@ -1293,7 +1291,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope(const Token *Tok1, const c
|
||||||
}
|
}
|
||||||
|
|
||||||
// detect cases that "simplifycode" don't handle well..
|
// detect cases that "simplifycode" don't handle well..
|
||||||
else if (_settings._debug)
|
else if (_settings->_debug)
|
||||||
{
|
{
|
||||||
Token *first = tok;
|
Token *first = tok;
|
||||||
while (first && first->str() == ";")
|
while (first && first->str() == ";")
|
||||||
|
@ -1441,12 +1439,12 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_ParseClass(const Token *
|
||||||
if (Token::Match(tok->next(), "%type% * %var% ;"))
|
if (Token::Match(tok->next(), "%type% * %var% ;"))
|
||||||
{
|
{
|
||||||
// No false positives for auto deallocated classes..
|
// No false positives for auto deallocated classes..
|
||||||
if (_settings.isAutoDealloc(tok->strAt(1)))
|
if (_settings->isAutoDealloc(tok->strAt(1)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (tok->isName() || Token::Match(tok, "[;}]"))
|
if (tok->isName() || Token::Match(tok, "[;}]"))
|
||||||
{
|
{
|
||||||
if (_settings._showAll || !isclass(tok->tokAt(1)))
|
if (_settings->_showAll || !isclass(tok->tokAt(1)))
|
||||||
CheckMemoryLeak_ClassMembers_Variable(classname.back(), tok->tokAt(3));
|
CheckMemoryLeak_ClassMembers_Variable(classname.back(), tok->tokAt(3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1565,7 +1563,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak()
|
||||||
CheckMemoryLeak_InFunction();
|
CheckMemoryLeak_InFunction();
|
||||||
|
|
||||||
// Check that all class members are deallocated..
|
// Check that all class members are deallocated..
|
||||||
if (_settings._showAll)
|
if (_settings->_showAll)
|
||||||
CheckMemoryLeak_ClassMembers();
|
CheckMemoryLeak_ClassMembers();
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
|
@ -26,17 +26,31 @@
|
||||||
|
|
||||||
/** \brief Check for memory leaks */
|
/** \brief Check for memory leaks */
|
||||||
|
|
||||||
#include "tokenize.h"
|
#include "check.h"
|
||||||
#include "settings.h"
|
|
||||||
#include "errorlogger.h"
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class CheckMemoryLeakClass
|
class Token;
|
||||||
|
|
||||||
|
class CheckMemoryLeakClass : public Check
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CheckMemoryLeakClass(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger);
|
CheckMemoryLeakClass() : Check()
|
||||||
~CheckMemoryLeakClass();
|
{ }
|
||||||
|
|
||||||
|
CheckMemoryLeakClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
|
: Check(tokenizer, settings, errorLogger)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
|
{
|
||||||
|
CheckMemoryLeakClass checkMemoryLeakClass(tokenizer, settings, errorLogger);
|
||||||
|
checkMemoryLeakClass.CheckMemoryLeak();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void CheckMemoryLeak();
|
void CheckMemoryLeak();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -109,9 +123,6 @@ private:
|
||||||
AllocType GetReallocationType(const Token *tok2);
|
AllocType GetReallocationType(const Token *tok2);
|
||||||
bool isclass(const Token *typestr);
|
bool isclass(const Token *typestr);
|
||||||
|
|
||||||
const Tokenizer *_tokenizer;
|
|
||||||
ErrorLogger *_errorLogger;
|
|
||||||
const Settings _settings;
|
|
||||||
std::list<AllocFunc> _listAllocFunc;
|
std::list<AllocFunc> _listAllocFunc;
|
||||||
|
|
||||||
// Experimental functionality..
|
// Experimental functionality..
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
#include "checkother.h"
|
#include "checkother.h"
|
||||||
|
#include "tokenize.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -29,24 +31,15 @@
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Register this check class (by creating a static instance of it)
|
||||||
|
namespace
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
|
||||||
// Warning on C-Style casts.. p = (kalle *)foo;
|
|
||||||
//---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
CheckOther::CheckOther(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger)
|
|
||||||
: _settings(settings)
|
|
||||||
{
|
{
|
||||||
_tokenizer = tokenizer;
|
CheckOther instance;
|
||||||
_errorLogger = errorLogger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckOther::~CheckOther()
|
//---------------------------------------------------------------------------
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckOther::WarningOldStylePointerCast()
|
void CheckOther::WarningOldStylePointerCast()
|
||||||
{
|
{
|
||||||
|
@ -195,7 +188,7 @@ void CheckOther::redundantCondition2()
|
||||||
|
|
||||||
void CheckOther::WarningIf()
|
void CheckOther::WarningIf()
|
||||||
{
|
{
|
||||||
if (ErrorLogger::ifNoAction(_settings))
|
if (ErrorLogger::ifNoAction(*_settings))
|
||||||
{
|
{
|
||||||
// Search for 'if (condition);'
|
// Search for 'if (condition);'
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
|
@ -225,7 +218,7 @@ void CheckOther::WarningIf()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ErrorLogger::conditionAlwaysTrueFalse(_settings))
|
if (ErrorLogger::conditionAlwaysTrueFalse(*_settings))
|
||||||
{
|
{
|
||||||
// Search for 'a=b; if (a==b)'
|
// Search for 'a=b; if (a==b)'
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
|
@ -393,7 +386,7 @@ void CheckOther::CheckUnsignedDivision()
|
||||||
|
|
||||||
else if (!Token::Match(tok, "[).]") && Token::Match(tok->next(), "%var% / %var%"))
|
else if (!Token::Match(tok, "[).]") && Token::Match(tok->next(), "%var% / %var%"))
|
||||||
{
|
{
|
||||||
if (ErrorLogger::udivWarning(_settings))
|
if (ErrorLogger::udivWarning(*_settings))
|
||||||
{
|
{
|
||||||
const char *varname1 = tok->strAt(1);
|
const char *varname1 = tok->strAt(1);
|
||||||
const char *varname2 = tok->strAt(3);
|
const char *varname2 = tok->strAt(3);
|
||||||
|
|
|
@ -23,14 +23,46 @@
|
||||||
#define CheckOtherH
|
#define CheckOtherH
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "tokenize.h"
|
#include "check.h"
|
||||||
#include "errorlogger.h"
|
#include "settings.h"
|
||||||
|
|
||||||
class CheckOther
|
class Token;
|
||||||
|
|
||||||
|
class CheckOther : public Check
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CheckOther(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger);
|
CheckOther() : Check()
|
||||||
~CheckOther();
|
{ }
|
||||||
|
|
||||||
|
CheckOther(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
|
: Check(tokenizer, settings, errorLogger)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: run these before simplification..
|
||||||
|
// checkOther.CheckUnsignedDivision();
|
||||||
|
// checkOther.CheckCharVariable();
|
||||||
|
|
||||||
|
|
||||||
|
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
|
{
|
||||||
|
CheckOther checkOther(tokenizer, settings, errorLogger);
|
||||||
|
|
||||||
|
if (settings->_checkCodingStyle)
|
||||||
|
{
|
||||||
|
checkOther.WarningOldStylePointerCast();
|
||||||
|
checkOther.WarningRedundantCode();
|
||||||
|
checkOther.WarningIf();
|
||||||
|
checkOther.CheckVariableScope();
|
||||||
|
checkOther.CheckConstantFunctionParameter();
|
||||||
|
checkOther.CheckStructMemberUsage();
|
||||||
|
checkOther.CheckIncompleteStatement();
|
||||||
|
}
|
||||||
|
|
||||||
|
checkOther.strPlusChar();
|
||||||
|
checkOther.returnPointerToStackData();
|
||||||
|
checkOther.InvalidFunctionUsage();
|
||||||
|
}
|
||||||
|
|
||||||
// Casting
|
// Casting
|
||||||
void WarningOldStylePointerCast();
|
void WarningOldStylePointerCast();
|
||||||
|
@ -75,10 +107,6 @@ protected:
|
||||||
// if (haystack.find(needle) != haystack.end())
|
// if (haystack.find(needle) != haystack.end())
|
||||||
// haystack.remove(needle);
|
// haystack.remove(needle);
|
||||||
void redundantCondition2();
|
void redundantCondition2();
|
||||||
|
|
||||||
const Tokenizer *_tokenizer;
|
|
||||||
ErrorLogger *_errorLogger;
|
|
||||||
const Settings &_settings;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
|
@ -21,10 +21,6 @@
|
||||||
#include "preprocessor.h" // preprocessor.
|
#include "preprocessor.h" // preprocessor.
|
||||||
#include "tokenize.h" // <- Tokenizer
|
#include "tokenize.h" // <- Tokenizer
|
||||||
|
|
||||||
#include "checkmemoryleak.h"
|
|
||||||
#include "checkdangerousfunctions.h"
|
|
||||||
#include "checkheaders.h"
|
|
||||||
#include "checkother.h"
|
|
||||||
#include "checkfunctionusage.h"
|
#include "checkfunctionusage.h"
|
||||||
#include "filelister.h"
|
#include "filelister.h"
|
||||||
|
|
||||||
|
@ -382,75 +378,13 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
||||||
|
|
||||||
_tokenizer.fillFunctionList();
|
_tokenizer.fillFunctionList();
|
||||||
|
|
||||||
// Coding style checks that must be run before the simplifyTokenList
|
|
||||||
CheckOther checkOther(&_tokenizer, _settings, this);
|
|
||||||
|
|
||||||
// Check for unsigned divisions where one operand is signed
|
|
||||||
if (ErrorLogger::udivWarning(_settings) || ErrorLogger::udivError())
|
|
||||||
checkOther.CheckUnsignedDivision();
|
|
||||||
|
|
||||||
// Give warning when using char variable as array index
|
|
||||||
if (ErrorLogger::charArrayIndex(_settings) || ErrorLogger::charBitOp(_settings))
|
|
||||||
checkOther.CheckCharVariable();
|
|
||||||
|
|
||||||
_tokenizer.simplifyTokenList();
|
_tokenizer.simplifyTokenList();
|
||||||
|
|
||||||
// Write simplified token list to a file..
|
|
||||||
//std::cout << _tokenizer.tokens()->stringifyList(true) << std::endl;
|
|
||||||
|
|
||||||
if (_settings._unusedFunctions)
|
if (_settings._unusedFunctions)
|
||||||
_checkFunctionUsage.parseTokens(_tokenizer);
|
_checkFunctionUsage.parseTokens(_tokenizer);
|
||||||
|
|
||||||
// Class for checking functions that should not be used
|
// Run all checks in all registered Check classes
|
||||||
CheckDangerousFunctionsClass checkDangerousFunctions(&_tokenizer, _settings, this);
|
|
||||||
|
|
||||||
// Memory leak
|
|
||||||
CheckMemoryLeakClass checkMemoryLeak(&_tokenizer, _settings, this);
|
|
||||||
if (ErrorLogger::memleak() || ErrorLogger::mismatchAllocDealloc())
|
|
||||||
checkMemoryLeak.CheckMemoryLeak();
|
|
||||||
|
|
||||||
// Warning upon c-style pointer casts
|
|
||||||
if (ErrorLogger::cstyleCast(_settings))
|
|
||||||
{
|
|
||||||
const char *ext = strrchr(FileName, '.');
|
|
||||||
if (ext && strcmp(ext, ".cpp") == 0)
|
|
||||||
checkOther.WarningOldStylePointerCast();
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (a) delete a;
|
|
||||||
if (ErrorLogger::redundantIfDelete0(_settings))
|
|
||||||
checkOther.WarningRedundantCode();
|
|
||||||
|
|
||||||
// strtol and strtoul usage
|
|
||||||
if (ErrorLogger::dangerousUsageStrtol() ||
|
|
||||||
ErrorLogger::sprintfOverlappingData())
|
|
||||||
checkOther.InvalidFunctionUsage();
|
|
||||||
|
|
||||||
// if (condition);
|
|
||||||
if (ErrorLogger::ifNoAction(_settings) || ErrorLogger::conditionAlwaysTrueFalse(_settings))
|
|
||||||
checkOther.WarningIf();
|
|
||||||
|
|
||||||
// Unused struct members..
|
|
||||||
if (ErrorLogger::unusedStructMember(_settings))
|
|
||||||
checkOther.CheckStructMemberUsage();
|
|
||||||
|
|
||||||
// Check if a constant function parameter is passed by value
|
|
||||||
if (ErrorLogger::passedByValue(_settings))
|
|
||||||
checkOther.CheckConstantFunctionParameter();
|
|
||||||
|
|
||||||
// Variable scope (check if the scope could be limited)
|
|
||||||
if (ErrorLogger::variableScope())
|
|
||||||
checkOther.CheckVariableScope();
|
|
||||||
|
|
||||||
// Check for various types of incomplete statements that could for example
|
|
||||||
// mean that an ';' has been added by accident
|
|
||||||
if (ErrorLogger::constStatement(_settings))
|
|
||||||
checkOther.CheckIncompleteStatement();
|
|
||||||
|
|
||||||
// Unusual pointer arithmetic
|
|
||||||
if (ErrorLogger::strPlusChar())
|
|
||||||
checkOther.strPlusChar();
|
|
||||||
|
|
||||||
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)->runChecks(&_tokenizer, &_settings, this);
|
(*it)->runChecks(&_tokenizer, &_settings, this);
|
||||||
|
|
|
@ -53,7 +53,8 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Check char variable usage..
|
// Check char variable usage..
|
||||||
CheckOther checkOther(&tokenizer, Settings(), this);
|
Settings settings;
|
||||||
|
CheckOther checkOther(&tokenizer, &settings, this);
|
||||||
checkOther.CheckCharVariable();
|
checkOther.CheckCharVariable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ private:
|
||||||
// Check for buffer overruns..
|
// Check for buffer overruns..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings._showAll = true;
|
settings._showAll = true;
|
||||||
CheckDangerousFunctionsClass checkDangerousFunctions(&tokenizer, settings, this);
|
CheckDangerousFunctionsClass checkDangerousFunctions(&tokenizer, &settings, this);
|
||||||
checkDangerousFunctions.dangerousFunctions();
|
checkDangerousFunctions.dangerousFunctions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ private:
|
||||||
settings._checkCodingStyle = true;
|
settings._checkCodingStyle = true;
|
||||||
|
|
||||||
// Check for unsigned divisions..
|
// Check for unsigned divisions..
|
||||||
CheckOther checkOther(&tokenizer, settings, this);
|
CheckOther checkOther(&tokenizer, &settings, this);
|
||||||
checkOther.CheckUnsignedDivision();
|
checkOther.CheckUnsignedDivision();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ private:
|
||||||
settings._showAll = true;
|
settings._showAll = true;
|
||||||
|
|
||||||
// Check for unused variables..
|
// Check for unused variables..
|
||||||
CheckOther checkOther(&tokenizer, settings, this);
|
CheckOther checkOther(&tokenizer, &settings, this);
|
||||||
checkOther.CheckIncompleteStatement();
|
checkOther.CheckIncompleteStatement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ private:
|
||||||
settings._debug = true;
|
settings._debug = true;
|
||||||
settings._showAll = showAll;
|
settings._showAll = showAll;
|
||||||
tokenizer.fillFunctionList();
|
tokenizer.fillFunctionList();
|
||||||
CheckMemoryLeakClass checkMemoryLeak(&tokenizer, settings, this);
|
CheckMemoryLeakClass checkMemoryLeak(&tokenizer, &settings, this);
|
||||||
checkMemoryLeak.CheckMemoryLeak();
|
checkMemoryLeak.CheckMemoryLeak();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1981,7 +1981,7 @@ private:
|
||||||
settings.autoDealloc(istr);
|
settings.autoDealloc(istr);
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckMemoryLeakClass checkMemoryLeak(&tokenizer, settings, this);
|
CheckMemoryLeakClass checkMemoryLeak(&tokenizer, &settings, this);
|
||||||
checkMemoryLeak.CheckMemoryLeak();
|
checkMemoryLeak.CheckMemoryLeak();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ public:
|
||||||
class OurCheckMemoryLeakClass : public CheckMemoryLeakClass
|
class OurCheckMemoryLeakClass : public CheckMemoryLeakClass
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OurCheckMemoryLeakClass(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger)
|
OurCheckMemoryLeakClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
: CheckMemoryLeakClass(tokenizer, settings, errorLogger)
|
: CheckMemoryLeakClass(tokenizer, settings, errorLogger)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ private:
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
OurCheckMemoryLeakClass checkMemoryLeak(&tokenizer, settings, this);
|
OurCheckMemoryLeakClass checkMemoryLeak(&tokenizer, &settings, this);
|
||||||
Token *tok = checkMemoryLeak.functionParameterCode(tokenizer.tokens(), 1);
|
Token *tok = checkMemoryLeak.functionParameterCode(tokenizer.tokens(), 1);
|
||||||
|
|
||||||
// Compare tokens..
|
// Compare tokens..
|
||||||
|
|
|
@ -63,7 +63,8 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Check for redundant code..
|
// Check for redundant code..
|
||||||
CheckOther checkOther(&tokenizer, Settings(), this);
|
Settings settings;
|
||||||
|
CheckOther checkOther(&tokenizer, &settings, this);
|
||||||
checkOther.WarningRedundantCode();
|
checkOther.WarningRedundantCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +130,8 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Check for redundant code..
|
// Check for redundant code..
|
||||||
CheckOther checkOther(&tokenizer, Settings(), this);
|
Settings settings;
|
||||||
|
CheckOther checkOther(&tokenizer, &settings, this);
|
||||||
checkOther.InvalidFunctionUsage();
|
checkOther.InvalidFunctionUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +198,8 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Check for redundant code..
|
// Check for redundant code..
|
||||||
CheckOther checkOther(&tokenizer, Settings(), this);
|
Settings settings;
|
||||||
|
CheckOther checkOther(&tokenizer, &settings, this);
|
||||||
checkOther.strPlusChar();
|
checkOther.strPlusChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +249,8 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Check for redundant code..
|
// Check for redundant code..
|
||||||
CheckOther checkOther(&tokenizer, Settings(), this);
|
Settings settings;
|
||||||
|
CheckOther checkOther(&tokenizer, &settings, this);
|
||||||
checkOther.returnPointerToStackData();
|
checkOther.returnPointerToStackData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
class OurCheckOther : public CheckOther
|
class OurCheckOther : public CheckOther
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OurCheckOther(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger)
|
OurCheckOther(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
: CheckOther(tokenizer, settings, errorLogger)
|
: CheckOther(tokenizer, settings, errorLogger)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -63,7 +63,8 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Check for redundant condition..
|
// Check for redundant condition..
|
||||||
OurCheckOther checkOther(&tokenizer, Settings(), this);
|
Settings settings;
|
||||||
|
OurCheckOther checkOther(&tokenizer, &settings, this);
|
||||||
checkOther.redundantCondition2();
|
checkOther.redundantCondition2();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,8 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Check for unused variables..
|
// Check for unused variables..
|
||||||
CheckOther checkOther(&tokenizer, Settings(), this);
|
Settings settings;
|
||||||
|
CheckOther checkOther(&tokenizer, &settings, this);
|
||||||
checkOther.CheckStructMemberUsage();
|
checkOther.CheckStructMemberUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue