diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index b244cd9d3..497343f74 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -26,7 +26,6 @@ #include "threadexecutor.h" #include "utils.h" -#include #include // EXIT_SUCCESS and EXIT_FAILURE #include #include diff --git a/cli/filelister.cpp b/cli/filelister.cpp index 9ac6ea5fe..c117ba39f 100644 --- a/cli/filelister.cpp +++ b/cli/filelister.cpp @@ -21,7 +21,6 @@ #include "pathmatch.h" #include #include -#include #ifdef _WIN32 @@ -114,7 +113,7 @@ void FileLister::recursiveAddFiles(std::map &files, co continue; const char* ansiFfd = ffd.cFileName; - if (strchr(ansiFfd,'?')) { + if (std::strchr(ansiFfd,'?')) { ansiFfd = ffd.cAlternateFileName; } @@ -122,9 +121,9 @@ void FileLister::recursiveAddFiles(std::map &files, co if ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { // File - const std::string nativename = Path::fromNativeSeparators(fname); - if ((!checkAllFilesInDir || Path::acceptFile(fname, extra)) && !ignored.Match(fname)) { + const std::string nativename = Path::fromNativeSeparators(fname); + // Limitation: file sizes are assumed to fit in a 'size_t' #ifdef _WIN64 files[nativename] = (static_cast(ffd.nFileSizeHigh) << 32) | ffd.nFileSizeLow; @@ -168,6 +167,7 @@ bool FileLister::fileExists(const std::string &path) #include #include #include +#include // Get absolute path. Returns empty string if path does not exist or other error. std::string FileLister::getAbsolutePath(const std::string& path) diff --git a/cli/main.cpp b/cli/main.cpp index b813ddf13..9e32158cd 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -102,7 +102,7 @@ void CheckOther::checkZeroDivision() #include "cppcheckexecutor.h" -#include +#include #include #ifdef _WIN32 @@ -136,11 +136,11 @@ int main(int argc, char* argv[]) return exec.check(argc, argv); #ifdef NDEBUG } catch (const InternalError& e) { - printf("%s\n", e.errorMessage.c_str()); + std::cout << e.errorMessage << std::endl; } catch (const std::exception& error) { - printf("%s\n", error.what()); + std::cout << error.what() << std::endl; } catch (...) { - printf("Unknown exception\n"); + std::cout << "Unknown exception" << std::endl; } return EXIT_FAILURE; #endif diff --git a/lib/check.cpp b/lib/check.cpp index a97181745..fa994e0e5 100644 --- a/lib/check.cpp +++ b/lib/check.cpp @@ -17,8 +17,6 @@ */ //--------------------------------------------------------------------------- -// 64-bit portability -//--------------------------------------------------------------------------- #include "check.h" diff --git a/lib/checkbufferoverrun.h b/lib/checkbufferoverrun.h index 290467160..9ad87b4e8 100644 --- a/lib/checkbufferoverrun.h +++ b/lib/checkbufferoverrun.h @@ -75,9 +75,6 @@ public: /** @brief negative size for array */ void negativeArraySize(); - /** @brief %Check for buffer overruns by inspecting execution paths */ - void executionPaths(); - /** * @brief Get minimum length of format string result * @param input_string format string diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 430497535..43408f18b 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -23,10 +23,10 @@ #include "token.h" #include "errorlogger.h" #include "symboldatabase.h" +#include "utils.h" #include #include -#include //--------------------------------------------------------------------------- diff --git a/lib/checkinternal.cpp b/lib/checkinternal.cpp index 1bca4d398..ba18d5eb8 100644 --- a/lib/checkinternal.cpp +++ b/lib/checkinternal.cpp @@ -23,7 +23,6 @@ #include #include #include -#include // Register this check class (by creating a static instance of it). // Disabled in release builds diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 7a3a1ccb1..b828a667e 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -21,6 +21,7 @@ #include "tokenize.h" #include "symboldatabase.h" +#include "utils.h" #include #include diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index c5141c729..b8f5efdce 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -22,9 +22,9 @@ #include "mathlib.h" #include "tokenize.h" #include "astutils.h" +#include "utils.h" #include -#include #include #include @@ -2060,12 +2060,9 @@ void CheckMemoryLeakInFunction::checkScope(const Token *startTok, const std::str noerr = noerr || Token::simpleMatch(first, "alloc ; if return ; dealloc; }"); // Unhandled case.. - if (!noerr) { - std::ostringstream errmsg; - errmsg << "inconclusive leak of " << varname << ": "; - errmsg << tok->stringifyList(false, false, false, false, false, 0, 0); - reportError(first, Severity::debug, "debug", errmsg.str()); - } + if (!noerr) + reportError(first, Severity::debug, "debug", + "inconclusive leak of " + varname + ": " + tok->stringifyList(false, false, false, false, false, 0, 0)); } TokenList::deleteTokens(tok); diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 09f815dfe..36913b4af 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -21,6 +21,7 @@ #include "checknullpointer.h" #include "mathlib.h" #include "symboldatabase.h" +#include "utils.h" #include //--------------------------------------------------------------------------- diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 6d17ffdc8..b7d0454a6 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -22,8 +22,8 @@ #include "astutils.h" #include "mathlib.h" #include "symboldatabase.h" +#include "utils.h" -#include // fabs() #include #include // find_if() //--------------------------------------------------------------------------- diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index f893ff8a8..dc464125c 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -19,6 +19,7 @@ #include "checkstl.h" #include "symboldatabase.h" #include "checknullpointer.h" +#include "utils.h" #include // Register this check class (by creating a static instance of it) @@ -1476,7 +1477,7 @@ void CheckStl::readingEmptyStlContainer() bool insert = false; if (var->nameToken() == tok && var->isLocal() && !var->isStatic()) { // Local variable declared insert = !Token::Match(tok->tokAt(1), "[(=]"); // Only if not initialized - } else if (Token::Match(tok, "%name% . clear ( ) ;")) { + } else if (Token::Match(tok, "%var% . clear ( ) ;")) { insert = true; } diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index a2bbcf45c..23c53128f 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -21,9 +21,8 @@ #include "checkuninitvar.h" #include "astutils.h" #include "mathlib.h" -#include "checknullpointer.h" // CheckNullPointer::parseFunctionCall +#include "checknullpointer.h" // CheckNullPointer::isPointerDeref #include "symboldatabase.h" -#include #include #include #include @@ -172,10 +171,9 @@ void CheckUninitVar::checkStruct(const Token *tok, const Variable &structvar) } struct VariableValue { - VariableValue() : notEqual(false), value(0) {} - explicit VariableValue(MathLib::bigint val) : notEqual(false), value(val) {} - bool notEqual; + explicit VariableValue(MathLib::bigint val = 0) : value(val), notEqual(false) {} MathLib::bigint value; + bool notEqual; }; static VariableValue operator!(VariableValue v) { diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 926e6e33e..adc057ae7 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -21,7 +21,6 @@ #include "checkunusedvar.h" #include "symboldatabase.h" #include -#include #include //--------------------------------------------------------------------------- diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index 8419d970b..c18736d1a 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include InternalError::InternalError(const Token *tok, const std::string &errorMsg, Type type) : token(tok), errorMessage(errorMsg) @@ -131,7 +131,8 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data) _inconclusive = false; _callStack.clear(); std::istringstream iss(data); - std::vector results; + std::array results; + std::size_t elem = 0; while (iss.good()) { unsigned int len = 0; if (!(iss >> len)) @@ -149,12 +150,12 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data) continue; } - results.push_back(temp); - if (results.size() == 5) + results[elem++] = temp; + if (elem == 5) break; } - if (results.size() != 5) + if (elem != 5) throw InternalError(0, "Internal Error: Deserialization of error message failed"); _id = results[0]; diff --git a/lib/errorlogger.h b/lib/errorlogger.h index 8d8153a73..3b1061870 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -21,12 +21,12 @@ #define errorloggerH //--------------------------------------------------------------------------- -#include -#include - #include "config.h" #include "suppressions.h" +#include +#include + class Token; class TokenList; diff --git a/lib/library.cpp b/lib/library.cpp index 95e04efd3..409033183 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -26,7 +26,6 @@ #include "astutils.h" #include -#include static std::vector getnames(const char *names) { diff --git a/lib/library.h b/lib/library.h index 988ef2bd0..b6b0c27a8 100644 --- a/lib/library.h +++ b/lib/library.h @@ -23,7 +23,6 @@ #include "config.h" #include "mathlib.h" -#include "token.h" #include "standards.h" #include "errorlogger.h" @@ -31,8 +30,8 @@ #include #include #include +#include -class TokenList; namespace tinyxml2 { class XMLDocument; class XMLElement; diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index c75c14786..e6c65f6e0 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -23,6 +23,7 @@ #include #include +#include #include diff --git a/lib/mathlib.h b/lib/mathlib.h index eba2a5931..3aadbdf2f 100644 --- a/lib/mathlib.h +++ b/lib/mathlib.h @@ -21,7 +21,6 @@ #define mathlibH //--------------------------------------------------------------------------- -#include #include #include #include "config.h" diff --git a/lib/settings.cpp b/lib/settings.cpp index 9542b5e9c..43055d095 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -17,7 +17,6 @@ */ #include "settings.h" -#include "path.h" #include "preprocessor.h" // Preprocessor #include "utils.h" diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index cd5994b7b..f79ad5130 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -17,7 +17,6 @@ */ #include "suppressions.h" -#include "settings.h" #include "path.h" #include diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 24f62f944..4d2e308af 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -23,6 +23,7 @@ #include "token.h" #include "settings.h" #include "errorlogger.h" +#include "utils.h" #include #include diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index 60fb7957d..fe77afadd 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -31,7 +31,6 @@ #include "config.h" #include "token.h" #include "mathlib.h" -#include "utils.h" class Tokenizer; class Settings; diff --git a/lib/token.cpp b/lib/token.cpp index c2d82476f..fcb550fd8 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -18,9 +18,9 @@ #include "token.h" #include "errorlogger.h" -#include "check.h" #include "settings.h" #include "symboldatabase.h" +#include "utils.h" #include #include #include diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b2dbd692d..9c1f4765f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -16,7 +16,6 @@ * along with this program. If not, see . */ - //--------------------------------------------------------------------------- #include "tokenize.h" #include "mathlib.h" @@ -26,6 +25,7 @@ #include "symboldatabase.h" #include "templatesimplifier.h" #include "timer.h" +#include "utils.h" #include #include diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 3ab4b1244..5cf7cb0df 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -29,7 +29,6 @@ #include #include #include -#include // How many compileExpression recursions are allowed? // For practical code this could be endless. But in some special torture test diff --git a/test/testrunner.cpp b/test/testrunner.cpp index 87f892a64..8b7a34a1d 100644 --- a/test/testrunner.cpp +++ b/test/testrunner.cpp @@ -19,9 +19,8 @@ #include "testsuite.h" #include "preprocessor.h" #include "options.h" -#include +#include #include -#include int main(int argc, char *argv[]) { @@ -41,11 +40,11 @@ int main(int argc, char *argv[]) return (failedTestsCount == 0) ? EXIT_SUCCESS : EXIT_FAILURE; #ifdef NDEBUG } catch (const InternalError& e) { - printf("%s\n", e.errorMessage.c_str()); + std::cout << e.errorMessage << std::endl; } catch (const std::exception& error) { - printf("%s\n", error.what()); + std::cout << error.what() << std::endl; } catch (...) { - printf("Unknown exception\n"); + std::cout << "Unknown exception" << std::endl; } return EXIT_FAILURE; #endif diff --git a/test/testsamples.cpp b/test/testsamples.cpp index e4f440c37..d485d26d7 100644 --- a/test/testsamples.cpp +++ b/test/testsamples.cpp @@ -21,6 +21,7 @@ #include "cppcheckexecutor.h" #include "path.h" #include "pathmatch.h" +#include "redirect.h" #include #include #include diff --git a/test/testsuite.cpp b/test/testsuite.cpp index f81a41afa..c20c0576d 100644 --- a/test/testsuite.cpp +++ b/test/testsuite.cpp @@ -18,9 +18,9 @@ #include "testsuite.h" #include "options.h" +#include "redirect.h" #include -#include #include std::ostringstream errout; diff --git a/test/testsuite.h b/test/testsuite.h index 76b0b6d2c..414f6de87 100644 --- a/test/testsuite.h +++ b/test/testsuite.h @@ -23,7 +23,6 @@ #include #include #include "errorlogger.h" -#include "redirect.h" class options; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 317dd2df3..d815d7dfa 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -19,6 +19,7 @@ #include "testsuite.h" #include "testutils.h" #include "symboldatabase.h" +#include "utils.h" #include #include