From 0f7071a00050337fb86dad492f8200dd8c9be1b3 Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Thu, 12 Jun 2014 19:58:43 +0200 Subject: [PATCH] Fix clang and coverity warnings --- cli/main.cpp | 2 +- lib/checkmemoryleak.cpp | 14 ++++++-------- lib/library.cpp | 9 +++++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/cli/main.cpp b/cli/main.cpp index 3fb01ce61..6f24d8556 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -97,6 +97,7 @@ void CheckOther::checkZeroDivision() #ifdef _WIN32 #include +static char exename[1024] = {0}; #endif /** @@ -115,7 +116,6 @@ int main(int argc, char* argv[]) CppCheckExecutor exec; #ifdef _WIN32 - char exename[1024] = {0}; GetModuleFileNameA(NULL, exename, sizeof(exename)/sizeof(exename[0])-1); argv[0] = exename; #endif diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index f79ad8f38..1a776d526 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -425,14 +425,12 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Function* f if (varid == 0) return No; - if (this != nullptr) { - // If variable is not local then alloctype shall be "No" - // Todo: there can be false negatives about mismatching allocation/deallocation. - // => Generate "alloc ; use ;" if variable is not local? - const Variable *var = tokenizer->getSymbolDatabase()->getVariableFromVarId(varid); - if (!var || !var->isLocal() || var->isStatic()) - return No; - } + // If variable is not local then alloctype shall be "No" + // Todo: there can be false negatives about mismatching allocation/deallocation. + // => Generate "alloc ; use ;" if variable is not local? + const Variable *var = tokenizer->getSymbolDatabase()->getVariableFromVarId(varid); + if (!var || !var->isLocal() || var->isStatic()) + return No; // Check if return pointer is allocated.. AllocType allocType = No; diff --git a/lib/library.cpp b/lib/library.cpp index aa7441bba..15fa7ac0a 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -289,10 +289,11 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) else if (strcmp(markupnode->Name(), "codeblocks") == 0) { for (const tinyxml2::XMLElement *blocknode = markupnode->FirstChildElement(); blocknode; blocknode = blocknode->NextSiblingElement()) { - if (strcmp(blocknode->Name(), "block") == 0) - _executableblocks[extension].addBlock(blocknode->Attribute("name")); - - else if (strcmp(blocknode->Name(), "structure") == 0) { + if (strcmp(blocknode->Name(), "block") == 0) { + const char * name = blocknode->Attribute("name"); + if (name) + _executableblocks[extension].addBlock(blocknode->Attribute("name")); + } else if (strcmp(blocknode->Name(), "structure") == 0) { const char * start = blocknode->Attribute("start"); if (start) _executableblocks[extension].setStart(start);