From 8c70778b70fb25f031cc2ecca26c6ff36e6ce52e Mon Sep 17 00:00:00 2001 From: PKEuS Date: Tue, 4 Sep 2012 15:29:51 +0200 Subject: [PATCH] Refactorization: Fixed several messages when self-checking cppcheck --- cli/filelister.cpp | 1 - lib/checkbufferoverrun.cpp | 4 +--- lib/checkmemoryleak.cpp | 6 ++---- lib/preprocessor.cpp | 5 +---- lib/tokenize.cpp | 8 ++------ 5 files changed, 6 insertions(+), 18 deletions(-) diff --git a/cli/filelister.cpp b/cli/filelister.cpp index 515a58d3d..d03035845 100644 --- a/cli/filelister.cpp +++ b/cli/filelister.cpp @@ -138,7 +138,6 @@ void FileLister::recursiveAddFiles(std::map &files, co if (INVALID_HANDLE_VALUE != hFind) { FindClose(hFind); - hFind = INVALID_HANDLE_VALUE; } } diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index cc4929e5a..6ef144253 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -823,11 +823,9 @@ void CheckBufferOverrun::arrayIndexInForLoop(const Token *tok, const ArrayInfo & } } - bool usedInArray = false; - if (max_value > size) { if (tok3->strAt(1) == ")") { - + bool usedInArray = false; for (const Token *loopTok = tok3->tokAt(2); loopTok->str() != "}" ; loopTok = loopTok->next()) { if (loopTok->varId() == arrayInfo.varid() && loopTok->tokAt(2)->varId() == counter_varid) usedInArray = true; diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 7c3b8b39c..a3d74dc57 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -772,18 +772,16 @@ static void addtoken(Token **rettail, const Token *tok, const std::string &str) Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list 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 // is used in a if-condition then generate "ifv" instead of "if". std::set extravar; // The first token should be ";" - rethead = new Token(0); + Token* rethead = new Token(0); rethead->str(";"); rethead->linenr(tok->linenr()); rethead->fileIndex(tok->fileIndex()); - rettail = rethead; + Token* rettail = rethead; int indentlevel = 0; int parlevel = 0; diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index cd5d3e728..8ff74f2af 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -905,10 +905,8 @@ std::string Preprocessor::getdef(std::string line, bool def) if (line.compare(0, 12, "#if defined ") == 0) line.erase(0, 11); else if (line.compare(0, 15, "#elif !defined(") == 0) { - std::string::size_type pos = 0; - 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 // about the mismatch 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 endfilePos = 0; std::set handledFiles; - endfilePos = pos; while ((pos = code.find("#include", pos)) != std::string::npos) { // Accept only includes that are at the start of a line if (pos > 0 && code[pos-1] != '\n') { diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 237a4ee96..a97a6d828 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1123,14 +1123,13 @@ void Tokenizer::simplifyTypedef() // classes, casts, operators, and template parameters // try to determine which category this substitution is - bool isDerived = false; bool inCast = false; bool inTemplate = false; bool inOperator = false; bool inSizeof = false; // 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(A) // todo: check for more complicated casts like: (const some_typedef *)A @@ -3755,10 +3754,7 @@ bool Tokenizer::removeRedundantConditions() continue; // Find matching else - Token *elseTag = 0; - - // Find the closing "}" - elseTag = tok->linkAt(4)->next(); + Token *elseTag = tok->linkAt(4)->next(); bool boolValue = (tok->strAt(2) == "true");