Refactoring: Rename member functions to follow naming guidelines.

This commit is contained in:
Reijo Tomperi 2009-07-05 23:16:43 +03:00
parent f676deb208
commit 8b0e481d46
26 changed files with 163 additions and 162 deletions

View File

@ -60,6 +60,8 @@
<Unit filename="gui/threadhandler.h" /> <Unit filename="gui/threadhandler.h" />
<Unit filename="gui/threadresult.cpp" /> <Unit filename="gui/threadresult.cpp" />
<Unit filename="gui/threadresult.h" /> <Unit filename="gui/threadresult.h" />
<Unit filename="gui/translationhandler.cpp" />
<Unit filename="gui/translationhandler.h" />
<Unit filename="gui/txtreport.cpp" /> <Unit filename="gui/txtreport.cpp" />
<Unit filename="gui/txtreport.h" /> <Unit filename="gui/txtreport.h" />
<Unit filename="gui/xmlreport.cpp" /> <Unit filename="gui/xmlreport.cpp" />

View File

@ -349,7 +349,7 @@ QStringList MainWindow::RemoveUnacceptedFiles(const QStringList &list)
QString str; QString str;
foreach(str, list) foreach(str, list)
{ {
if (FileLister::AcceptFile(str.toStdString())) if (FileLister::acceptFile(str.toStdString()))
{ {
result << str; result << str;
} }

View File

@ -82,7 +82,7 @@ void CheckBufferOverrunClass::sizeArgumentAsChar(const Token *tok)
// Check array usage.. // Check array usage..
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, const char *varname[], const int size, const int total_size, unsigned int varid) void CheckBufferOverrunClass::checkScope(const Token *tok, const char *varname[], const int size, const int total_size, unsigned int varid)
{ {
unsigned int varc = 0; unsigned int varc = 0;
@ -390,7 +390,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
continue; continue;
// Find function.. // Find function..
const Token *ftok = _tokenizer->GetFunctionTokenByName(tok->str().c_str()); const Token *ftok = _tokenizer->getFunctionTokenByName(tok->str().c_str());
if (!ftok) if (!ftok)
continue; continue;
@ -422,7 +422,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
// Check variable usage in the function.. // Check variable usage in the function..
_callStack.push_back(tok); _callStack.push_back(tok);
CheckBufferOverrun_CheckScope(ftok, parname, size, total_size, 0); checkScope(ftok, parname, size, total_size, 0);
_callStack.pop_back(); _callStack.pop_back();
// break out.. // break out..
@ -440,7 +440,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
// Checking local variables in a scope // Checking local variables in a scope
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckBufferOverrunClass::CheckBufferOverrun_GlobalAndLocalVariable() void CheckBufferOverrunClass::checkGlobalAndLocalVariable()
{ {
int indentlevel = 0; int indentlevel = 0;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
@ -493,13 +493,13 @@ void CheckBufferOverrunClass::CheckBufferOverrun_GlobalAndLocalVariable()
continue; continue;
} }
int total_size = size * ((*type == '*') ? 4 : _tokenizer->SizeOfType(type)); int total_size = size * ((*type == '*') ? 4 : _tokenizer->sizeOfType(type));
if (total_size == 0) if (total_size == 0)
continue; continue;
// The callstack is empty // The callstack is empty
_callStack.clear(); _callStack.clear();
CheckBufferOverrun_CheckScope(tok->tokAt(nextTok), varname, size, total_size, varid); checkScope(tok->tokAt(nextTok), varname, size, total_size, varid);
} }
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -509,7 +509,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_GlobalAndLocalVariable()
// Checking member variables of structs.. // Checking member variables of structs..
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckBufferOverrunClass::CheckBufferOverrun_StructVariable() void CheckBufferOverrunClass::checkStructVariable()
{ {
const char declstruct[] = "struct|class %var% {"; const char declstruct[] = "struct|class %var% {";
for (const Token *tok = Token::findmatch(_tokenizer->tokens(), declstruct); for (const Token *tok = Token::findmatch(_tokenizer->tokens(), declstruct);
@ -538,7 +538,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_StructVariable()
const char *varname[3] = {0, 0, 0}; const char *varname[3] = {0, 0, 0};
varname[1] = tok2->strAt(ivar); varname[1] = tok2->strAt(ivar);
int arrsize = std::atoi(tok2->strAt(ivar + 2)); int arrsize = std::atoi(tok2->strAt(ivar + 2));
int total_size = arrsize * _tokenizer->SizeOfType(tok2->strAt(1)); int total_size = arrsize * _tokenizer->sizeOfType(tok2->strAt(1));
if (total_size == 0) if (total_size == 0)
continue; continue;
@ -558,7 +558,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_StructVariable()
if (Token::simpleMatch(tok4, ") {")) if (Token::simpleMatch(tok4, ") {"))
{ {
const char *names[2] = {varname[1], 0}; const char *names[2] = {varname[1], 0};
CheckBufferOverrun_CheckScope(tok4->tokAt(2), names, arrsize, total_size, 0); checkScope(tok4->tokAt(2), names, arrsize, total_size, 0);
break; break;
} }
} }
@ -615,7 +615,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_StructVariable()
continue; continue;
// Check variable usage.. // Check variable usage..
CheckBufferOverrun_CheckScope(CheckTok, varname, arrsize, total_size, 0); checkScope(CheckTok, varname, arrsize, total_size, 0);
} }
} }
} }
@ -624,8 +624,8 @@ void CheckBufferOverrunClass::CheckBufferOverrun_StructVariable()
void CheckBufferOverrunClass::bufferOverrun() void CheckBufferOverrunClass::bufferOverrun()
{ {
CheckBufferOverrun_GlobalAndLocalVariable(); checkGlobalAndLocalVariable();
CheckBufferOverrun_StructVariable(); checkStructVariable();
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -55,13 +55,13 @@ public:
private: private:
/** Check for buffer overruns - locate struct variables and check them with the .._CheckScope function */ /** Check for buffer overruns - locate struct variables and check them with the .._CheckScope function */
void CheckBufferOverrun_StructVariable(); void checkStructVariable();
/** Check for buffer overruns - locate global variables and local function variables and check them with the .._CheckScope function */ /** Check for buffer overruns - locate global variables and local function variables and check them with the checkScope function */
void CheckBufferOverrun_GlobalAndLocalVariable(); void checkGlobalAndLocalVariable();
/** Check for buffer overruns - this is the function that performs the actual checking */ /** Check for buffer overruns - this is the function that performs the actual checking */
void CheckBufferOverrun_CheckScope(const Token *tok, const char *varname[], const int size, const int total_size, unsigned int varid); void checkScope(const Token *tok, const char *varname[], const int size, const int total_size, unsigned int varid);
/** callstack - used during intra-function checking */ /** callstack - used during intra-function checking */
std::list<const Token *> _callStack; std::list<const Token *> _callStack;

View File

@ -41,7 +41,7 @@ CheckClass instance;
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
struct CheckClass::VAR *CheckClass::ClassChecking_GetVarList(const Token *tok1, bool withClasses) struct CheckClass::VAR *CheckClass::getVarList(const Token *tok1, bool withClasses)
{ {
// Get variable list.. // Get variable list..
struct VAR *varlist = NULL; struct VAR *varlist = NULL;
@ -136,7 +136,7 @@ struct CheckClass::VAR *CheckClass::ClassChecking_GetVarList(const Token *tok1,
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckClass::InitVar(struct VAR *varlist, const char varname[]) void CheckClass::initVar(struct VAR *varlist, const char varname[])
{ {
for (struct VAR *var = varlist; var; var = var->next) for (struct VAR *var = varlist; var; var = var->next)
{ {
@ -149,7 +149,7 @@ void CheckClass::InitVar(struct VAR *varlist, const char varname[])
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckClass::ClassChecking_VarList_Initialize(const Token *tok1, const Token *ftok, struct VAR *varlist, const char classname[], std::list<std::string> &callstack) void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, struct VAR *varlist, const char classname[], std::list<std::string> &callstack)
{ {
bool Assign = false; bool Assign = false;
unsigned int indentlevel = 0; unsigned int indentlevel = 0;
@ -165,7 +165,7 @@ void CheckClass::ClassChecking_VarList_Initialize(const Token *tok1, const Token
{ {
if (Assign && Token::Match(ftok, "%var% (")) if (Assign && Token::Match(ftok, "%var% ("))
{ {
InitVar(varlist, ftok->str().c_str()); initVar(varlist, ftok->str().c_str());
} }
Assign |= (ftok->str() == ":"); Assign |= (ftok->str() == ":");
@ -191,7 +191,7 @@ void CheckClass::ClassChecking_VarList_Initialize(const Token *tok1, const Token
// Variable getting value from stream? // Variable getting value from stream?
if (Token::Match(ftok, ">> %var%")) if (Token::Match(ftok, ">> %var%"))
{ {
InitVar(varlist, ftok->next()->str().c_str()); initVar(varlist, ftok->next()->str().c_str());
} }
// Before a new statement there is "[{};)=]" or "else" // Before a new statement there is "[{};)=]" or "else"
@ -232,21 +232,21 @@ void CheckClass::ClassChecking_VarList_Initialize(const Token *tok1, const Token
{ {
callstack.push_back(ftok->str()); callstack.push_back(ftok->str());
int i = 0; int i = 0;
const Token *ftok2 = Tokenizer::FindClassFunction(tok1, classname, ftok->str().c_str(), i); const Token *ftok2 = Tokenizer::findClassFunction(tok1, classname, ftok->str().c_str(), i);
ClassChecking_VarList_Initialize(tok1, ftok2, varlist, classname, callstack); initializeVarList(tok1, ftok2, varlist, classname, callstack);
} }
} }
// Assignment of member variable? // Assignment of member variable?
else if (Token::Match(ftok, "%var% =")) else if (Token::Match(ftok, "%var% ="))
{ {
InitVar(varlist, ftok->str().c_str()); initVar(varlist, ftok->str().c_str());
} }
// The functions 'clear' and 'Clear' are supposed to initialize variable. // The functions 'clear' and 'Clear' are supposed to initialize variable.
if (Token::Match(ftok, "%var% . clear|Clear (")) if (Token::Match(ftok, "%var% . clear|Clear ("))
{ {
InitVar(varlist, ftok->str().c_str()); initVar(varlist, ftok->str().c_str());
} }
} }
} }
@ -331,7 +331,7 @@ void CheckClass::constructors()
if (ErrorLogger::noConstructor(*_settings)) if (ErrorLogger::noConstructor(*_settings))
{ {
// If the class has member variables there should be an constructor // If the class has member variables there should be an constructor
struct VAR *varlist = ClassChecking_GetVarList(tok1, false); struct VAR *varlist = getVarList(tok1, false);
if (varlist) if (varlist)
{ {
noConstructorError(tok1, classNameToken->str()); noConstructorError(tok1, classNameToken->str());
@ -350,27 +350,27 @@ void CheckClass::constructors()
} }
// Check constructors // Check constructors
CheckConstructors(tok1, className[0]); checkConstructors(tok1, className[0]);
// Check assignment operators // Check assignment operators
CheckConstructors(tok1, "operator ="); checkConstructors(tok1, "operator =");
tok1 = Token::findmatch(tok1->next(), pattern_class); tok1 = Token::findmatch(tok1->next(), pattern_class);
} }
} }
void CheckClass::CheckConstructors(const Token *tok1, const char funcname[]) void CheckClass::checkConstructors(const Token *tok1, const char funcname[])
{ {
const char * const className = tok1->strAt(1); const char * const className = tok1->strAt(1);
// Check that all member variables are initialized.. // Check that all member variables are initialized..
bool withClasses = bool(_settings->_showAll && std::string(funcname) == "operator ="); bool withClasses = bool(_settings->_showAll && std::string(funcname) == "operator =");
struct VAR *varlist = ClassChecking_GetVarList(tok1, withClasses); struct VAR *varlist = getVarList(tok1, withClasses);
int indentlevel = 0; int indentlevel = 0;
const Token *constructor_token = Tokenizer::FindClassFunction(tok1, className, funcname, indentlevel); const Token *constructor_token = Tokenizer::findClassFunction(tok1, className, funcname, indentlevel);
std::list<std::string> callstack; std::list<std::string> callstack;
ClassChecking_VarList_Initialize(tok1, constructor_token, varlist, className, callstack); initializeVarList(tok1, constructor_token, varlist, className, callstack);
while (constructor_token) while (constructor_token)
{ {
// Check if any variables are uninitialized // Check if any variables are uninitialized
@ -415,9 +415,9 @@ void CheckClass::CheckConstructors(const Token *tok1, const char funcname[])
for (struct VAR *var = varlist; var; var = var->next) for (struct VAR *var = varlist; var; var = var->next)
var->init = false; var->init = false;
constructor_token = Tokenizer::FindClassFunction(constructor_token->next(), className, funcname, indentlevel); constructor_token = Tokenizer::findClassFunction(constructor_token->next(), className, funcname, indentlevel);
callstack.clear(); callstack.clear();
ClassChecking_VarList_Initialize(tok1, constructor_token, varlist, className, callstack); initializeVarList(tok1, constructor_token, varlist, className, callstack);
} }
// Delete the varlist.. // Delete the varlist..

View File

@ -90,12 +90,12 @@ private:
struct VAR *next; struct VAR *next;
}; };
void ClassChecking_VarList_Initialize(const Token *tok1, const Token *ftok, struct VAR *varlist, const char classname[], std::list<std::string> &callstack); void initializeVarList(const Token *tok1, const Token *ftok, struct VAR *varlist, const char classname[], std::list<std::string> &callstack);
void InitVar(struct VAR *varlist, const char varname[]); void initVar(struct VAR *varlist, const char varname[]);
struct VAR *ClassChecking_GetVarList(const Token *tok1, bool withClasses); struct VAR *getVarList(const Token *tok1, bool withClasses);
// Check constructors for a specified class // Check constructors for a specified class
void CheckConstructors(const Token *tok1, const char funcname[]); void checkConstructors(const Token *tok1, const char funcname[]);
// Reporting errors.. // Reporting errors..
void noConstructorError(const Token *tok, const std::string &classname); void noConstructorError(const Token *tok, const std::string &classname);

View File

@ -47,7 +47,7 @@ CheckHeaders::~CheckHeaders()
} }
void CheckHeaders::WarningHeaderWithImplementation() void CheckHeaders::warningHeaderWithImplementation()
{ {
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
@ -86,7 +86,7 @@ void CheckHeaders::WarningHeaderWithImplementation()
// HEADERS - Unneeded include // HEADERS - Unneeded include
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckHeaders::WarningIncludeHeader() void CheckHeaders::warningIncludeHeader()
{ {
// Including.. // Including..
for (const Token *includetok = _tokenizer->tokens(); includetok; includetok = includetok->next()) for (const Token *includetok = _tokenizer->tokens(); includetok; includetok = includetok->next())
@ -99,7 +99,7 @@ void CheckHeaders::WarningIncludeHeader()
const char *includefile = includetok->strAt(1); const char *includefile = includetok->strAt(1);
while (hfile < _tokenizer->getFiles()->size()) while (hfile < _tokenizer->getFiles()->size())
{ {
if (FileLister::SameFileName(_tokenizer->getFiles()->at(hfile).c_str(), includefile)) if (FileLister::sameFileName(_tokenizer->getFiles()->at(hfile).c_str(), includefile))
break; break;
++hfile; ++hfile;
} }

View File

@ -30,8 +30,8 @@ class CheckHeaders
public: public:
CheckHeaders(const Tokenizer *tokenizer, ErrorLogger *errorLogger); CheckHeaders(const Tokenizer *tokenizer, ErrorLogger *errorLogger);
~CheckHeaders(); ~CheckHeaders();
void WarningHeaderWithImplementation(); void warningHeaderWithImplementation();
void WarningIncludeHeader(); void warningIncludeHeader();
private: private:
const Tokenizer *_tokenizer; const Tokenizer *_tokenizer;

View File

@ -51,7 +51,7 @@ bool CheckMemoryLeak::isclass(const Tokenizer *_tokenizer, const Token *tok) con
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
CheckMemoryLeak::AllocType CheckMemoryLeak::GetAllocationType(const Token *tok2) const CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2) const
{ {
// What we may have... // What we may have...
// * var = (char *)malloc(10); // * var = (char *)malloc(10);
@ -131,7 +131,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::GetAllocationType(const Token *tok2)
CheckMemoryLeak::AllocType CheckMemoryLeak::GetReallocationType(const Token *tok2) CheckMemoryLeak::AllocType CheckMemoryLeak::getReallocationType(const Token *tok2)
{ {
// What we may have... // What we may have...
// * var = (char *)realloc(..; // * var = (char *)realloc(..;
@ -155,7 +155,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::GetReallocationType(const Token *tok
} }
CheckMemoryLeak::AllocType CheckMemoryLeak::GetDeallocationType(const Token *tok, const char *varnames[]) CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok, const char *varnames[])
{ {
int i = 0; int i = 0;
std::string names; std::string names;
@ -207,7 +207,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::GetDeallocationType(const Token *tok
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
void CheckMemoryLeak::MemoryLeak(const Token *tok, const char varname[], AllocType alloctype, bool all) void CheckMemoryLeak::memoryLeak(const Token *tok, const char varname[], AllocType alloctype, bool all)
{ {
if (alloctype == CheckMemoryLeak::File || if (alloctype == CheckMemoryLeak::File ||
alloctype == CheckMemoryLeak::Pipe || alloctype == CheckMemoryLeak::Pipe ||
@ -308,7 +308,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Token *tok)
if (varname.empty() && Token::Match(tok, "%var% = ")) if (varname.empty() && Token::Match(tok, "%var% = "))
{ {
varname = tok->str(); varname = tok->str();
allocType = GetAllocationType(tok->tokAt(2)); allocType = getAllocationType(tok->tokAt(2));
if (allocType == No) if (allocType == No)
return No; return No;
while (tok && tok->str() != ";") while (tok && tok->str() != ";")
@ -335,7 +335,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Token *tok)
bool CheckMemoryLeakInFunction::MatchFunctionsThatReturnArg(const Token *tok, const std::string &varname) bool CheckMemoryLeakInFunction::matchFunctionsThatReturnArg(const Token *tok, const std::string &varname)
{ {
return Token::Match(tok, std::string("; " + varname + " = strcat|memcpy|memmove|strcpy ( " + varname + " ,").c_str()); return Token::Match(tok, std::string("; " + varname + " = strcat|memcpy|memmove|strcpy ( " + varname + " ,").c_str());
} }
@ -426,7 +426,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
if (tok->str() == "delete") if (tok->str() == "delete")
return 0; return 0;
if (GetAllocationType(tok) != No || GetReallocationType(tok) != No || GetDeallocationType(tok, varnames) != No) if (getAllocationType(tok) != No || getReallocationType(tok) != No || getDeallocationType(tok, varnames) != No)
return 0; return 0;
if (callstack.size() > 2) if (callstack.size() > 2)
@ -442,7 +442,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
// Check if this is a function that allocates memory.. // Check if this is a function that allocates memory..
{ {
const Token *ftok = _tokenizer->GetFunctionTokenByName(funcname.c_str()); const Token *ftok = _tokenizer->getFunctionTokenByName(funcname.c_str());
AllocType a = functionReturnType(ftok); AllocType a = functionReturnType(ftok);
if (a != No) if (a != No)
return "alloc"; return "alloc";
@ -485,7 +485,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
++par; ++par;
if (Token::Match(tok, pattern.c_str())) if (Token::Match(tok, pattern.c_str()))
{ {
const Token *ftok = _tokenizer->GetFunctionTokenByName(funcname.c_str()); const Token *ftok = _tokenizer->getFunctionTokenByName(funcname.c_str());
if (!ftok) if (!ftok)
return "use"; return "use";
@ -583,7 +583,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
if (Token::Match(tok->previous(), std::string("[(;{}] " + varnameStr + " =").c_str())) if (Token::Match(tok->previous(), std::string("[(;{}] " + varnameStr + " =").c_str()))
{ {
AllocType alloc = GetAllocationType(tok->tokAt(2)); AllocType alloc = getAllocationType(tok->tokAt(2));
bool realloc = false; bool realloc = false;
if (sz > 1 && if (sz > 1 &&
@ -595,7 +595,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
if (alloc == No) if (alloc == No)
{ {
alloc = GetReallocationType(tok->tokAt(2)); alloc = getReallocationType(tok->tokAt(2));
if (alloc != No) if (alloc != No)
{ {
addtoken("realloc"); addtoken("realloc");
@ -649,7 +649,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
alloctype = alloc; alloctype = alloc;
} }
else if (MatchFunctionsThatReturnArg(tok->previous(), std::string(varname))) else if (matchFunctionsThatReturnArg(tok->previous(), std::string(varname)))
{ {
addtoken("use"); addtoken("use");
} }
@ -678,7 +678,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
if (Token::Match(tok->previous(), "[;{})=] %var%")) if (Token::Match(tok->previous(), "[;{})=] %var%"))
{ {
AllocType dealloc = GetDeallocationType(tok, varnames); AllocType dealloc = getDeallocationType(tok, varnames);
if (dealloc != No) if (dealloc != No)
{ {
addtoken("dealloc"); addtoken("dealloc");
@ -1535,23 +1535,23 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const char varname
if ((result = Token::findmatch(tok, "loop alloc ;")) != NULL) if ((result = Token::findmatch(tok, "loop alloc ;")) != NULL)
{ {
MemoryLeak(result, varname, alloctype, all); memoryLeak(result, varname, alloctype, all);
} }
else if ((result = Token::findmatch(tok, "alloc ; if break|continue|return ;")) != NULL else if ((result = Token::findmatch(tok, "alloc ; if break|continue|return ;")) != NULL
&& Token::findmatch(tok, "dealloc ; alloc ; if continue ;") == NULL) && Token::findmatch(tok, "dealloc ; alloc ; if continue ;") == NULL)
{ {
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);
} }
else if ((result = Token::findmatch(tok, "alloc ; alloc|assign|return callfunc| ;")) != NULL) else if ((result = Token::findmatch(tok, "alloc ; alloc|assign|return callfunc| ;")) != NULL)
{ {
MemoryLeak(result->tokAt(2), varname, alloctype, all); memoryLeak(result->tokAt(2), varname, alloctype, all);
} }
else if ((result = Token::findmatch(tok, "dealloc ; dealloc ;")) != NULL) else if ((result = Token::findmatch(tok, "dealloc ; dealloc ;")) != NULL)
@ -1566,7 +1566,7 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const char varname
const Token *last = tok; const Token *last = tok;
while (last->next()) while (last->next())
last = last->next(); last = last->next();
MemoryLeak(last, varname, alloctype, all); memoryLeak(last, varname, alloctype, all);
} }
// detect cases that "simplifycode" don't handle well.. // detect cases that "simplifycode" don't handle well..
@ -1650,7 +1650,7 @@ void CheckMemoryLeakInFunction::check()
// Declare a local variable => Check // Declare a local variable => Check
if (indentlevel > 0 && infunc) if (indentlevel > 0 && infunc)
{ {
unsigned int sz = _tokenizer->SizeOfType(tok->strAt(1)); unsigned int sz = _tokenizer->sizeOfType(tok->strAt(1));
if (sz < 1) if (sz < 1)
sz = 1; sz = 1;
@ -1789,7 +1789,7 @@ void CheckMemoryLeakInClass::variable(const char classname[], const Token *tokVa
// Loop through all tokens. Inspect member functions // Loop through all tokens. Inspect member functions
int indent_ = 0; int indent_ = 0;
const Token *functionToken = Tokenizer::FindClassFunction(_tokenizer->tokens(), classname, "~| %var%", indent_); const Token *functionToken = Tokenizer::findClassFunction(_tokenizer->tokens(), classname, "~| %var%", indent_);
while (functionToken) while (functionToken)
{ {
int indent = 0; int indent = 0;
@ -1817,7 +1817,7 @@ void CheckMemoryLeakInClass::variable(const char classname[], const Token *tokVa
// Allocate.. // Allocate..
if (indent == 0 || Token::Match(tok, (std::string(varname) + " =").c_str())) if (indent == 0 || Token::Match(tok, (std::string(varname) + " =").c_str()))
{ {
AllocType alloc = GetAllocationType(tok->tokAt((indent > 0) ? 2 : 3)); AllocType alloc = getAllocationType(tok->tokAt((indent > 0) ? 2 : 3));
if (alloc != CheckMemoryLeak::No) if (alloc != CheckMemoryLeak::No)
{ {
if (Alloc != No && Alloc != alloc) if (Alloc != No && Alloc != alloc)
@ -1841,12 +1841,12 @@ void CheckMemoryLeakInClass::variable(const char classname[], const Token *tokVa
// Deallocate.. // Deallocate..
const char *varnames[3] = { "var", 0, 0 }; const char *varnames[3] = { "var", 0, 0 };
varnames[0] = varname; varnames[0] = varname;
AllocType dealloc = GetDeallocationType(tok, varnames); AllocType dealloc = getDeallocationType(tok, varnames);
if (dealloc == No) if (dealloc == No)
{ {
varnames[0] = "this"; varnames[0] = "this";
varnames[1] = varname; varnames[1] = varname;
dealloc = GetDeallocationType(tok, varnames); dealloc = getDeallocationType(tok, varnames);
} }
if (dealloc != CheckMemoryLeak::No) if (dealloc != CheckMemoryLeak::No)
{ {
@ -1867,12 +1867,12 @@ void CheckMemoryLeakInClass::variable(const char classname[], const Token *tokVa
} }
} }
functionToken = Tokenizer::FindClassFunction(functionToken->next(), classname, "~| %var%", indent_); functionToken = Tokenizer::findClassFunction(functionToken->next(), classname, "~| %var%", indent_);
} }
if (_settings->_showAll && Alloc != CheckMemoryLeak::No && Dealloc == CheckMemoryLeak::No) if (_settings->_showAll && Alloc != CheckMemoryLeak::No && Dealloc == CheckMemoryLeak::No)
{ {
MemoryLeak(tokVarname, (std::string(classname) + "::" + varname).c_str(), Alloc, true); memoryLeak(tokVarname, (std::string(classname) + "::" + varname).c_str(), Alloc, true);
} }
} }

View File

@ -49,11 +49,10 @@ public:
/** What type of allocation are used.. the "Many" means that several types of allocation and deallocation are used */ /** What type of allocation are used.. the "Many" means that several types of allocation and deallocation are used */
enum AllocType { No, Malloc, gMalloc, New, NewArray, File, Fd, Pipe, Dir, Many }; enum AllocType { No, Malloc, gMalloc, New, NewArray, File, Fd, Pipe, Dir, Many };
void MemoryLeak(const Token *tok, const char varname[], AllocType alloctype, bool all); void memoryLeak(const Token *tok, const char varname[], AllocType alloctype, bool all);
void MismatchError(const Token *Tok1, const std::list<const Token *> &callstack, const char varname[]); AllocType getDeallocationType(const Token *tok, const char *varnames[]);
AllocType GetDeallocationType(const Token *tok, const char *varnames[]); AllocType getAllocationType(const Token *tok2) const;
AllocType GetAllocationType(const Token *tok2) const; AllocType getReallocationType(const Token *tok2);
AllocType GetReallocationType(const Token *tok2);
bool isclass(const Tokenizer *_tokenizer, const Token *typestr) const; bool isclass(const Tokenizer *_tokenizer, const Token *typestr) const;
void memleakError(const Token *tok, const std::string &varname); void memleakError(const Token *tok, const std::string &varname);
@ -108,7 +107,7 @@ private:
private: private:
bool MatchFunctionsThatReturnArg(const Token *tok, const std::string &varname); bool matchFunctionsThatReturnArg(const Token *tok, const std::string &varname);
/** /**
* Check if there is a "!var" match inside a condition * Check if there is a "!var" match inside a condition

View File

@ -40,7 +40,7 @@ CheckOther instance;
void CheckOther::WarningOldStylePointerCast() void CheckOther::warningOldStylePointerCast()
{ {
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
@ -67,7 +67,7 @@ void CheckOther::WarningOldStylePointerCast()
// Redundant code.. // Redundant code..
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::WarningRedundantCode() void CheckOther::warningRedundantCode()
{ {
// if (p) delete p // if (p) delete p
@ -188,7 +188,7 @@ void CheckOther::redundantCondition2()
// if (condition) .... // if (condition) ....
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::WarningIf() void CheckOther::warningIf()
{ {
if (ErrorLogger::ifNoAction(*_settings)) if (ErrorLogger::ifNoAction(*_settings))
{ {
@ -306,7 +306,7 @@ void CheckOther::WarningIf()
// strtol(str, 0, radix) <- radix must be 0 or 2-36 // strtol(str, 0, radix) <- radix must be 0 or 2-36
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::InvalidFunctionUsage() void CheckOther::invalidFunctionUsage()
{ {
// strtol and strtoul.. // strtol and strtoul..
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
@ -389,7 +389,7 @@ void CheckOther::InvalidFunctionUsage()
// Check for unsigned divisions // Check for unsigned divisions
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::CheckUnsignedDivision() void CheckOther::checkUnsignedDivision()
{ {
// Check for "ivar / uvar" and "uvar / ivar" // Check for "ivar / uvar" and "uvar / ivar"
std::map<std::string, char> varsign; std::map<std::string, char> varsign;
@ -457,7 +457,7 @@ void CheckOther::CheckUnsignedDivision()
// Check scope of variables.. // Check scope of variables..
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::CheckVariableScope() void CheckOther::checkVariableScope()
{ {
// Walk through all tokens.. // Walk through all tokens..
bool func = false; bool func = false;
@ -530,7 +530,7 @@ void CheckOther::CheckVariableScope()
// Variable declaration? // Variable declaration?
if (Token::Match(tok1, "%type% %var% [;=]")) if (Token::Match(tok1, "%type% %var% [;=]"))
{ {
CheckVariableScope_LookupVar(tok1, tok1->strAt(1)); lookupVar(tok1, tok1->strAt(1));
} }
} }
} }
@ -538,7 +538,7 @@ void CheckOther::CheckVariableScope()
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::CheckVariableScope_LookupVar(const Token *tok1, const char varname[]) void CheckOther::lookupVar(const Token *tok1, const char varname[])
{ {
const Token *tok = tok1; const Token *tok = tok1;
@ -619,7 +619,7 @@ void CheckOther::CheckVariableScope_LookupVar(const Token *tok1, const char varn
// Check for constant function parameters // Check for constant function parameters
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::CheckConstantFunctionParameter() void CheckOther::checkConstantFunctionParameter()
{ {
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
@ -646,7 +646,7 @@ void CheckOther::CheckConstantFunctionParameter()
// Check that all struct members are used // Check that all struct members are used
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::CheckStructMemberUsage() void CheckOther::checkStructMemberUsage()
{ {
const char *structname = 0; const char *structname = 0;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
@ -716,7 +716,7 @@ void CheckOther::CheckStructMemberUsage()
// Check usage of char variables.. // Check usage of char variables..
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::CheckCharVariable() void CheckOther::checkCharVariable()
{ {
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
@ -790,7 +790,7 @@ void CheckOther::CheckCharVariable()
// Incomplete statement.. // Incomplete statement..
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::CheckIncompleteStatement() void CheckOther::checkIncompleteStatement()
{ {
int parlevel = 0; int parlevel = 0;
@ -951,7 +951,7 @@ void CheckOther::nullPointer()
void CheckOther::CheckZeroDivision() void CheckOther::checkZeroDivision()
{ {
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {

View File

@ -46,9 +46,9 @@ public:
if (settings->_checkCodingStyle) if (settings->_checkCodingStyle)
{ {
checkOther.WarningOldStylePointerCast(); checkOther.warningOldStylePointerCast();
checkOther.CheckUnsignedDivision(); checkOther.checkUnsignedDivision();
checkOther.CheckCharVariable(); checkOther.checkCharVariable();
} }
} }
@ -58,49 +58,49 @@ public:
if (settings->_checkCodingStyle) if (settings->_checkCodingStyle)
{ {
checkOther.WarningRedundantCode(); checkOther.warningRedundantCode();
checkOther.WarningIf(); checkOther.warningIf();
checkOther.CheckVariableScope(); checkOther.checkVariableScope();
checkOther.CheckConstantFunctionParameter(); checkOther.checkConstantFunctionParameter();
checkOther.CheckStructMemberUsage(); checkOther.checkStructMemberUsage();
checkOther.CheckIncompleteStatement(); checkOther.checkIncompleteStatement();
} }
checkOther.strPlusChar(); checkOther.strPlusChar();
checkOther.InvalidFunctionUsage(); checkOther.invalidFunctionUsage();
checkOther.nullPointer(); checkOther.nullPointer();
checkOther.CheckZeroDivision(); checkOther.checkZeroDivision();
} }
// Casting // Casting
void WarningOldStylePointerCast(); void warningOldStylePointerCast();
// Redundant code // Redundant code
void WarningRedundantCode(); void warningRedundantCode();
// Warning upon: if (condition); // Warning upon: if (condition);
void WarningIf(); void warningIf();
// Invalid function usage.. // Invalid function usage..
void InvalidFunctionUsage(); void invalidFunctionUsage();
// Check for unsigned division that might create bad results // Check for unsigned division that might create bad results
void CheckUnsignedDivision(); void checkUnsignedDivision();
// Check scope of variables // Check scope of variables
void CheckVariableScope(); void checkVariableScope();
// Check for constant function parameter // Check for constant function parameter
void CheckConstantFunctionParameter(); void checkConstantFunctionParameter();
// Check that all struct members are used // Check that all struct members are used
void CheckStructMemberUsage(); void checkStructMemberUsage();
// Using char variable as array index / as operand in bit operation // Using char variable as array index / as operand in bit operation
void CheckCharVariable(); void checkCharVariable();
// Incomplete statement. A statement that only contains a constant or variable // Incomplete statement. A statement that only contains a constant or variable
void CheckIncompleteStatement(); void checkIncompleteStatement();
/** str plus char */ /** str plus char */
void strPlusChar(); void strPlusChar();
@ -109,10 +109,10 @@ public:
void nullPointer(); void nullPointer();
/** Check zero division*/ /** Check zero division*/
void CheckZeroDivision(); void checkZeroDivision();
protected: protected:
void CheckVariableScope_LookupVar(const Token *tok1, const char varname[]); void lookupVar(const Token *tok1, const char varname[]);
// Redundant condition // Redundant condition
// if (haystack.find(needle) != haystack.end()) // if (haystack.find(needle) != haystack.end())

View File

@ -51,7 +51,7 @@ void CppCheck::settings(const Settings &settings)
void CppCheck::addFile(const std::string &path) void CppCheck::addFile(const std::string &path)
{ {
FileLister::RecursiveAddFiles(_filenames, path.c_str(), true); FileLister::recursiveAddFiles(_filenames, path.c_str(), true);
} }
void CppCheck::addFile(const std::string &path, const std::string &content) void CppCheck::addFile(const std::string &path, const std::string &content)
@ -255,10 +255,10 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
if (pathnames.size() > 0) if (pathnames.size() > 0)
{ {
// Execute RecursiveAddFiles() to each given file parameter // Execute recursiveAddFiles() to each given file parameter
std::vector<std::string>::const_iterator iter; std::vector<std::string>::const_iterator iter;
for (iter = pathnames.begin(); iter != pathnames.end(); iter++) for (iter = pathnames.begin(); iter != pathnames.end(); iter++)
FileLister::RecursiveAddFiles(_filenames, iter->c_str(), true); FileLister::recursiveAddFiles(_filenames, iter->c_str(), true);
} }
if (argc <= 1 || showHelp) if (argc <= 1 || showHelp)

View File

@ -88,7 +88,7 @@ std::string FileLister::simplifyPath(const char *originalPath)
bool FileLister::AcceptFile(const std::string &filename) bool FileLister::acceptFile(const std::string &filename)
{ {
std::string::size_type dotLocation = filename.find_last_of('.'); std::string::size_type dotLocation = filename.find_last_of('.');
if (dotLocation == std::string::npos) if (dotLocation == std::string::npos)
@ -115,7 +115,7 @@ bool FileLister::AcceptFile(const std::string &filename)
#if defined(__GNUC__) && !defined(__MINGW32__) #if defined(__GNUC__) && !defined(__MINGW32__)
// gcc / cygwin.. // gcc / cygwin..
void FileLister::RecursiveAddFiles(std::vector<std::string> &filenames, const std::string &path, bool recursive) void FileLister::recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path, bool recursive)
{ {
std::ostringstream oss; std::ostringstream oss;
oss << path; oss << path;
@ -135,13 +135,13 @@ void FileLister::RecursiveAddFiles(std::vector<std::string> &filenames, const st
// File // File
// If recursive is not used, accept all files given by user // If recursive is not used, accept all files given by user
if (!recursive || FileLister::AcceptFile(filename)) if (!recursive || FileLister::acceptFile(filename))
filenames.push_back(filename); filenames.push_back(filename);
} }
else if (recursive) else if (recursive)
{ {
// Directory // Directory
FileLister::RecursiveAddFiles(filenames, filename, recursive); FileLister::recursiveAddFiles(filenames, filename, recursive);
} }
} }
globfree(&glob_results); globfree(&glob_results);
@ -209,7 +209,7 @@ static HANDLE MyFindFirstFile(std::string path, LPWIN32_FIND_DATA findData)
#endif // defined(QT_CORE_LIB) #endif // defined(QT_CORE_LIB)
void FileLister::RecursiveAddFiles(std::vector<std::string> &filenames, const std::string &path, bool recursive) void FileLister::recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path, bool recursive)
{ {
// oss is the search string passed into FindFirst and FindNext. // oss is the search string passed into FindFirst and FindNext.
// bdir is the base directory which is used to form pathnames. // bdir is the base directory which is used to form pathnames.
@ -273,13 +273,13 @@ void FileLister::RecursiveAddFiles(std::vector<std::string> &filenames, const st
// File // File
// If recursive is not used, accept all files given by user // If recursive is not used, accept all files given by user
if (!recursive || FileLister::AcceptFile(ansiFfd)) if (!recursive || FileLister::acceptFile(ansiFfd))
filenames.push_back(fname.str()); filenames.push_back(fname.str());
} }
else if (recursive) else if (recursive)
{ {
// Directory // Directory
FileLister::RecursiveAddFiles(filenames, fname.str().c_str(), recursive); FileLister::recursiveAddFiles(filenames, fname.str().c_str(), recursive);
} }
#if defined(QT_CORE_LIB) #if defined(QT_CORE_LIB)
delete [] ansiFfd; delete [] ansiFfd;
@ -298,7 +298,7 @@ void FileLister::RecursiveAddFiles(std::vector<std::string> &filenames, const st
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool FileLister::SameFileName(const char fname1[], const char fname2[]) bool FileLister::sameFileName(const char fname1[], const char fname2[])
{ {
#ifdef __linux__ #ifdef __linux__
return bool(strcmp(fname1, fname2) == 0); return bool(strcmp(fname1, fname2) == 0);

View File

@ -27,8 +27,8 @@
#ifndef __GNUC__ #ifndef __GNUC__
#ifndef __BORLANDC__ #ifndef __BORLANDC__
#ifndef _MSC_VER #ifndef _MSC_VER
#error "C++Check must be compiled by either GCC/BORLAND/MSC to work fully.\n" #error "Cppcheck must be compiled by either GCC/BORLAND/MSC to work fully.\n"
#error "Please report that you couldn't compile c++check through the web page:\n" #error "Please report that you couldn't compile cppcheck through the web page:\n"
#error " https://sourceforge.net/projects/cppcheck/" #error " https://sourceforge.net/projects/cppcheck/"
#endif #endif
#endif #endif
@ -38,10 +38,10 @@
class FileLister class FileLister
{ {
public: public:
static void RecursiveAddFiles(std::vector<std::string> &filenames, const std::string &path, bool recursive); static void recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path, bool recursive);
static std::string simplifyPath(const char *originalPath); static std::string simplifyPath(const char *originalPath);
static bool SameFileName(const char fname1[], const char fname2[]); static bool sameFileName(const char fname1[], const char fname2[]);
static bool AcceptFile(const std::string &filename); static bool acceptFile(const std::string &filename);
private: private:
}; };

View File

@ -51,7 +51,7 @@ Tokenizer::Tokenizer(const Settings &settings, ErrorLogger *errorLogger)
Tokenizer::~Tokenizer() Tokenizer::~Tokenizer()
{ {
DeallocateTokens(); deallocateTokens();
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -118,7 +118,7 @@ void Tokenizer::addtoken(const char str[], const unsigned int lineno, const unsi
int Tokenizer::SizeOfType(const char type[]) const int Tokenizer::sizeOfType(const char type[]) const
{ {
if (!type) if (!type)
return 0; return 0;
@ -135,7 +135,7 @@ int Tokenizer::SizeOfType(const char type[]) const
// InsertTokens - Copy and insert tokens // InsertTokens - Copy and insert tokens
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void Tokenizer::InsertTokens(Token *dest, Token *src, unsigned int n) void Tokenizer::insertTokens(Token *dest, Token *src, unsigned int n)
{ {
while (n > 0) while (n > 0)
{ {
@ -222,7 +222,7 @@ void Tokenizer::createTokens(std::istream &code)
fileIndexes.push_back(FileIndex); fileIndexes.push_back(FileIndex);
for (unsigned int i = 0; i < _files.size(); i++) for (unsigned int i = 0; i < _files.size(); i++)
{ {
if (FileLister::SameFileName(_files[i].c_str(), line.c_str())) if (FileLister::sameFileName(_files[i].c_str(), line.c_str()))
{ {
// Use this index // Use this index
foundOurfile = true; foundOurfile = true;
@ -1269,7 +1269,7 @@ void Tokenizer::simplifyTokenList()
if (Token::Match(tok, "sizeof ( * )")) if (Token::Match(tok, "sizeof ( * )"))
{ {
std::ostringstream str; std::ostringstream str;
str << SizeOfType(tok->strAt(2)); str << sizeOfType(tok->strAt(2));
tok->str(str.str()); tok->str(str.str());
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
@ -1287,7 +1287,7 @@ void Tokenizer::simplifyTokenList()
else if (Token::Match(tok, "sizeof ( %type% )")) else if (Token::Match(tok, "sizeof ( %type% )"))
{ {
const char *type = tok->strAt(2); const char *type = tok->strAt(2);
int size = SizeOfType(type); int size = sizeOfType(type);
if (size > 0) if (size > 0)
{ {
std::ostringstream str; std::ostringstream str;
@ -1312,7 +1312,7 @@ void Tokenizer::simplifyTokenList()
const Token *decltok = Token::findmatch(_tokens, "%type% %varid% [", varid); const Token *decltok = Token::findmatch(_tokens, "%type% %varid% [", varid);
if (decltok) if (decltok)
{ {
sz = SizeOfType(decltok->strAt(0)); sz = sizeOfType(decltok->strAt(0));
} }
} }
@ -1336,7 +1336,7 @@ void Tokenizer::simplifyTokenList()
const int type_tok = ((tok->next()->str() == "*") ? 1 : 0); const int type_tok = ((tok->next()->str() == "*") ? 1 : 0);
int size = SizeOfType(tok->tokAt(type_tok)->str().c_str()); int size = sizeOfType(tok->tokAt(type_tok)->str().c_str());
if (size <= 0) if (size <= 0)
continue; continue;
@ -2205,7 +2205,7 @@ bool Tokenizer::simplifyVarDecl()
if (tok2->str() == ",") if (tok2->str() == ",")
{ {
tok2->str(";"); tok2->str(";");
InsertTokens(tok2, type0, typelen); insertTokens(tok2, type0, typelen);
} }
else else
@ -2233,14 +2233,14 @@ bool Tokenizer::simplifyVarDecl()
Token *VarTok = type0->tokAt(typelen); Token *VarTok = type0->tokAt(typelen);
while (Token::Match(VarTok, "*|const")) while (Token::Match(VarTok, "*|const"))
VarTok = VarTok->next(); VarTok = VarTok->next();
InsertTokens(eq, VarTok, 2); insertTokens(eq, VarTok, 2);
eq->str(";"); eq->str(";");
// "= x, " => "= x; type " // "= x, " => "= x; type "
if (tok2->str() == ",") if (tok2->str() == ",")
{ {
tok2->str(";"); tok2->str(";");
InsertTokens(tok2, type0, typelen); insertTokens(tok2, type0, typelen);
} }
break; break;
} }
@ -2754,7 +2754,7 @@ bool Tokenizer::simplifyCalculations()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
const Token *Tokenizer::GetFunctionTokenByName(const char funcname[]) const const Token *Tokenizer::getFunctionTokenByName(const char funcname[]) const
{ {
for (unsigned int i = 0; i < _functionList.size(); ++i) for (unsigned int i = 0; i < _functionList.size(); ++i)
{ {
@ -2852,7 +2852,7 @@ void Tokenizer::fillFunctionList()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Deallocate lists.. // Deallocate lists..
void Tokenizer::DeallocateTokens() void Tokenizer::deallocateTokens()
{ {
deleteTokens(_tokens); deleteTokens(_tokens);
_tokens = 0; _tokens = 0;
@ -2901,7 +2901,7 @@ std::string Tokenizer::file(const Token *tok) const
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
const Token * Tokenizer::FindClassFunction(const Token *tok, const char classname[], const char funcname[], int &indentlevel) const Token * Tokenizer::findClassFunction(const Token *tok, const char classname[], const char funcname[], int &indentlevel)
{ {
if (indentlevel < 0 || tok == NULL) if (indentlevel < 0 || tok == NULL)
return NULL; return NULL;

View File

@ -33,7 +33,7 @@ class Tokenizer
{ {
private: private:
// Deallocate lists.. // Deallocate lists..
void DeallocateTokens(); void deallocateTokens();
public: public:
Tokenizer(); Tokenizer();
@ -81,14 +81,14 @@ public:
std::string fileLine(const Token *tok) const; std::string fileLine(const Token *tok) const;
// Return size. // Return size.
int SizeOfType(const char type[]) const; int sizeOfType(const char type[]) const;
void initTokens(); void initTokens();
const std::vector<std::string> *getFiles() const; const std::vector<std::string> *getFiles() const;
void fillFunctionList(); void fillFunctionList();
const Token *GetFunctionTokenByName(const char funcname[]) const; const Token *getFunctionTokenByName(const char funcname[]) const;
const Token *tokens() const; const Token *tokens() const;
std::string file(const Token *tok) const; std::string file(const Token *tok) const;
@ -101,7 +101,7 @@ public:
* @param indentlevel Just an integer that you initialize to 0 before the first call. * @param indentlevel Just an integer that you initialize to 0 before the first call.
* @return First matching token or NULL. * @return First matching token or NULL.
*/ */
static const Token *FindClassFunction(const Token *tok, const char classname[], const char funcname[], int &indentlevel); static const Token *findClassFunction(const Token *tok, const char classname[], const char funcname[], int &indentlevel);
/** /**
@ -253,7 +253,7 @@ private:
*/ */
void simplifyTemplates(); void simplifyTemplates();
void InsertTokens(Token *dest, Token *src, unsigned int n); void insertTokens(Token *dest, Token *src, unsigned int n);
/** /**
* Setup links for tokens so that one can call Token::link(). * Setup links for tokens so that one can call Token::link().

View File

@ -57,7 +57,7 @@ private:
// Check char variable usage.. // Check char variable usage..
Settings settings; Settings settings;
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
checkOther.CheckCharVariable(); checkOther.checkCharVariable();
} }
void array_index() void array_index()

View File

@ -17,7 +17,7 @@
*/ */
// The preprocessor that c++check uses is a bit special. Instead of generating // The preprocessor that Cppcheck uses is a bit special. Instead of generating
// the code for a known configuration, it generates the code for each configuration. // the code for a known configuration, it generates the code for each configuration.

View File

@ -52,7 +52,7 @@ private:
// Check for unsigned divisions.. // Check for unsigned divisions..
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
checkOther.CheckUnsignedDivision(); checkOther.checkUnsignedDivision();
} }
void run() void run()

View File

@ -52,7 +52,7 @@ private:
// Check for unused variables.. // Check for unused variables..
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
checkOther.CheckIncompleteStatement(); checkOther.checkIncompleteStatement();
} }
void run() void run()

View File

@ -78,8 +78,8 @@ private:
// Check for redundant code.. // Check for redundant code..
Settings settings; Settings settings;
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
checkOther.WarningRedundantCode(); checkOther.warningRedundantCode();
checkOther.CheckZeroDivision(); checkOther.checkZeroDivision();
} }
@ -197,7 +197,7 @@ private:
// Check for redundant code.. // Check for redundant code..
Settings settings; Settings settings;
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
checkOther.InvalidFunctionUsage(); checkOther.invalidFunctionUsage();
} }
void sprintf1() void sprintf1()
@ -317,7 +317,7 @@ private:
Settings settings; Settings settings;
settings._checkCodingStyle = true; settings._checkCodingStyle = true;
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
checkOther.CheckVariableScope(); checkOther.checkVariableScope();
} }
void varScope1() void varScope1()
@ -445,7 +445,7 @@ private:
Settings settings; Settings settings;
settings._checkCodingStyle = true; settings._checkCodingStyle = true;
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
checkOther.WarningOldStylePointerCast(); checkOther.warningOldStylePointerCast();
} }
void oldStylePointerCast() void oldStylePointerCast()

View File

@ -17,7 +17,7 @@
*/ */
// The preprocessor that c++check uses is a bit special. Instead of generating // The preprocessor that Cppcheck uses is a bit special. Instead of generating
// the code for a known configuration, it generates the code for each configuration. // the code for a known configuration, it generates the code for each configuration.

View File

@ -17,7 +17,7 @@
*/ */
// The preprocessor that c++check uses is a bit special. Instead of generating // The preprocessor that Cppcheck uses is a bit special. Instead of generating
// the code for a known configuration, it generates the code for each configuration. // the code for a known configuration, it generates the code for each configuration.
@ -2060,9 +2060,9 @@ private:
int i; int i;
i = 0; i = 0;
const Token *tok = Tokenizer::FindClassFunction(tokenizer.tokens(), "Fred", "%var%", i); const Token *tok = Tokenizer::findClassFunction(tokenizer.tokens(), "Fred", "%var%", i);
ASSERT_EQUALS(true, Token::simpleMatch(tok, "Fred ( ) {")); ASSERT_EQUALS(true, Token::simpleMatch(tok, "Fred ( ) {"));
tok = Tokenizer::FindClassFunction(tok->next(), "Fred", "%var%", i); tok = Tokenizer::findClassFunction(tok->next(), "Fred", "%var%", i);
ASSERT_EQUALS(0, tok ? 1 : 0); ASSERT_EQUALS(0, tok ? 1 : 0);
} }

View File

@ -48,7 +48,7 @@ private:
// Check for unused variables.. // Check for unused variables..
Settings settings; Settings settings;
CheckOther checkOther(&tokenizer, &settings, this); CheckOther checkOther(&tokenizer, &settings, this);
checkOther.CheckStructMemberUsage(); checkOther.checkStructMemberUsage();
} }
void run() void run()

View File

@ -65,14 +65,14 @@ int main()
{ {
// Get files.. // Get files..
std::vector<std::string> srcfiles; std::vector<std::string> srcfiles;
FileLister::RecursiveAddFiles(srcfiles, "src/", true); FileLister::recursiveAddFiles(srcfiles, "src/", true);
if (srcfiles.empty()) if (srcfiles.empty())
{ {
std::cout << "No source files found." << std::endl; std::cout << "No source files found." << std::endl;
exit(1); exit(1);
} }
std::vector<std::string> testfiles; std::vector<std::string> testfiles;
FileLister::RecursiveAddFiles(testfiles, "test/", true); FileLister::recursiveAddFiles(testfiles, "test/", true);
std::ofstream fout("Makefile"); std::ofstream fout("Makefile");