Refactorization: Fixed several messages when self-checking cppcheck

This commit is contained in:
PKEuS 2012-09-04 15:29:51 +02:00
parent 8924e8af43
commit 8c70778b70
5 changed files with 6 additions and 18 deletions

View File

@ -138,7 +138,6 @@ void FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, co
if (INVALID_HANDLE_VALUE != hFind) { if (INVALID_HANDLE_VALUE != hFind) {
FindClose(hFind); FindClose(hFind);
hFind = INVALID_HANDLE_VALUE;
} }
} }

View File

@ -823,11 +823,9 @@ void CheckBufferOverrun::arrayIndexInForLoop(const Token *tok, const ArrayInfo &
} }
} }
bool usedInArray = false;
if (max_value > size) { if (max_value > size) {
if (tok3->strAt(1) == ")") { if (tok3->strAt(1) == ")") {
bool usedInArray = false;
for (const Token *loopTok = tok3->tokAt(2); loopTok->str() != "}" ; loopTok = loopTok->next()) { for (const Token *loopTok = tok3->tokAt(2); loopTok->str() != "}" ; loopTok = loopTok->next()) {
if (loopTok->varId() == arrayInfo.varid() && loopTok->tokAt(2)->varId() == counter_varid) if (loopTok->varId() == arrayInfo.varid() && loopTok->tokAt(2)->varId() == counter_varid)
usedInArray = true; usedInArray = true;

View File

@ -772,18 +772,16 @@ static void addtoken(Token **rettail, const Token *tok, const std::string &str)
Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Token *> callstack, const unsigned int varid, CheckMemoryLeak::AllocType &alloctype, CheckMemoryLeak::AllocType &dealloctype, bool classmember, unsigned int sz) Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Token *> callstack, const unsigned int varid, CheckMemoryLeak::AllocType &alloctype, CheckMemoryLeak::AllocType &dealloctype, bool classmember, unsigned int sz)
{ {
Token *rethead = 0, *rettail = 0;
// variables whose value depends on if(!var). If one of these variables // variables whose value depends on if(!var). If one of these variables
// is used in a if-condition then generate "ifv" instead of "if". // is used in a if-condition then generate "ifv" instead of "if".
std::set<unsigned int> extravar; std::set<unsigned int> extravar;
// The first token should be ";" // The first token should be ";"
rethead = new Token(0); Token* rethead = new Token(0);
rethead->str(";"); rethead->str(";");
rethead->linenr(tok->linenr()); rethead->linenr(tok->linenr());
rethead->fileIndex(tok->fileIndex()); rethead->fileIndex(tok->fileIndex());
rettail = rethead; Token* rettail = rethead;
int indentlevel = 0; int indentlevel = 0;
int parlevel = 0; int parlevel = 0;

View File

@ -905,10 +905,8 @@ std::string Preprocessor::getdef(std::string line, bool def)
if (line.compare(0, 12, "#if defined ") == 0) if (line.compare(0, 12, "#if defined ") == 0)
line.erase(0, 11); line.erase(0, 11);
else if (line.compare(0, 15, "#elif !defined(") == 0) { else if (line.compare(0, 15, "#elif !defined(") == 0) {
std::string::size_type pos = 0;
line.erase(0, 15); line.erase(0, 15);
pos = line.find(")"); std::string::size_type pos = line.find(")");
// if pos == ::npos then another part of the code will complain // if pos == ::npos then another part of the code will complain
// about the mismatch // about the mismatch
if (pos != std::string::npos) if (pos != std::string::npos)
@ -2024,7 +2022,6 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
std::string::size_type pos = 0; std::string::size_type pos = 0;
std::string::size_type endfilePos = 0; std::string::size_type endfilePos = 0;
std::set<std::string> handledFiles; std::set<std::string> handledFiles;
endfilePos = pos;
while ((pos = code.find("#include", pos)) != std::string::npos) { while ((pos = code.find("#include", pos)) != std::string::npos) {
// Accept only includes that are at the start of a line // Accept only includes that are at the start of a line
if (pos > 0 && code[pos-1] != '\n') { if (pos > 0 && code[pos-1] != '\n') {

View File

@ -1123,14 +1123,13 @@ void Tokenizer::simplifyTypedef()
// classes, casts, operators, and template parameters // classes, casts, operators, and template parameters
// try to determine which category this substitution is // try to determine which category this substitution is
bool isDerived = false;
bool inCast = false; bool inCast = false;
bool inTemplate = false; bool inTemplate = false;
bool inOperator = false; bool inOperator = false;
bool inSizeof = false; bool inSizeof = false;
// check for derived class: class A : some_typedef { // check for derived class: class A : some_typedef {
isDerived = Token::Match(tok2->previous(), "public|protected|private %type% {|,"); bool isDerived = Token::Match(tok2->previous(), "public|protected|private %type% {|,");
// check for cast: (some_typedef) A or static_cast<some_typedef>(A) // check for cast: (some_typedef) A or static_cast<some_typedef>(A)
// todo: check for more complicated casts like: (const some_typedef *)A // todo: check for more complicated casts like: (const some_typedef *)A
@ -3755,10 +3754,7 @@ bool Tokenizer::removeRedundantConditions()
continue; continue;
// Find matching else // Find matching else
Token *elseTag = 0; Token *elseTag = tok->linkAt(4)->next();
// Find the closing "}"
elseTag = tok->linkAt(4)->next();
bool boolValue = (tok->strAt(2) == "true"); bool boolValue = (tok->strAt(2) == "true");