CppcheckExecutor() : ErrorLogger() , stoptime(std::time(NULL)+2U) , cppcheck(*this,false) { cppcheck.settings().addEnabled("all"); cppcheck.settings().inconclusive = true; }
void run(const char code[]) { printf("%s\n", ErrorLogger::ErrorMessage::getXMLHeader(2).c_str()); cppcheck.check("test.c", code); printf("%s\n", ErrorLogger::ErrorMessage::getXMLFooter(2).c_str()); printf("\n\n"); }
void reportProgress(const std::string &filename, const char stage[], const unsigned int value) { if (std::time(NULL) >= stoptime) { printf("time to analyse the " "code is more than 1 " "second. terminating." "\n\n"); cppcheck.terminate(); } }
/* * That is a method which gets called from check_wrapper * */ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const char* const argv[]) { Settings& settings = cppcheck.settings(); _settings = &settings; bool std = tryLoadLibrary(settings.library, argv[0], "std.cfg"); bool posix = true; if (settings.standards.posix) posix = tryLoadLibrary(settings.library, argv[0], "posix.cfg"); bool windows = true; if (settings.isWindowsPlatform()) windows = tryLoadLibrary(settings.library, argv[0], "windows.cfg"); if (!std || !posix || !windows) { const std::list<ErrorLogger::ErrorMessage::FileLocation> callstack; const std::string msg("Failed to load " + std::string(!std ? "std.cfg" : !posix ? "posix.cfg" : "windows.cfg") + ". Your Cppcheck installation is broken, please re-install."); #ifdef CFGDIR const std::string details("The Cppcheck binary was compiled with CFGDIR set to \"" + std::string(CFGDIR) + "\" and will therefore search for " "std.cfg in that path."); #else const std::string cfgfolder(Path::fromNativeSeparators(Path::getPathFromFilename(argv[0])) + "cfg"); const std::string details("The Cppcheck binary was compiled without CFGDIR set. Either the " "std.cfg should be available in " + cfgfolder + " or the CFGDIR " "should be configured."); #endif ErrorLogger::ErrorMessage errmsg(callstack, Severity::information, msg+" "+details, "failedToLoadCfg", false); reportErr(errmsg); return EXIT_FAILURE; } if (settings.reportProgress) time1 = std::time(0); if (settings._xml) { reportErr(ErrorLogger::ErrorMessage::getXMLHeader(settings._xml_version)); } unsigned int returnValue = 0; if (settings._jobs == 1) { // Single process settings.jointSuppressionReport = true; std::size_t totalfilesize = 0; for (std::map<std::string, std::size_t>::const_iterator i = _files.begin(); i != _files.end(); ++i) { totalfilesize += i->second; } std::size_t processedsize = 0; unsigned int c = 0; for (std::map<std::string, std::size_t>::const_iterator i = _files.begin(); i != _files.end(); ++i) { if (!_settings->library.markupFile(i->first) || !_settings->library.processMarkupAfterCode(i->first)) { returnValue += cppcheck.check(i->first); processedsize += i->second; if (!settings.quiet) reportStatus(c + 1, _files.size(), processedsize, totalfilesize); c++; } } // second loop to parse all markup files which may not work until all // c/cpp files have been parsed and checked for (std::map<std::string, std::size_t>::const_iterator i = _files.begin(); i != _files.end(); ++i) { if (_settings->library.markupFile(i->first) && _settings->library.processMarkupAfterCode(i->first)) { returnValue += cppcheck.check(i->first); processedsize += i->second; if (!settings.quiet) reportStatus(c + 1, _files.size(), processedsize, totalfilesize); c++; } } cppcheck.analyseWholeProgram(); } else if (!ThreadExecutor::isEnabled()) { std::cout << "No thread support yet implemented for this platform." << std::endl; } else { // Multiple processes ThreadExecutor executor(_files, settings, *this); returnValue = executor.check(); } if (settings.isEnabled("information") || settings.checkConfiguration) { const bool enableUnusedFunctionCheck = cppcheck.unusedFunctionCheckIsEnabled(); if (settings.jointSuppressionReport) { for (std::map<std::string, std::size_t>::const_iterator i = _files.begin(); i != _files.end(); ++i) { reportUnmatchedSuppressions(settings.nomsg.getUnmatchedLocalSuppressions(i->first, enableUnusedFunctionCheck)); } } reportUnmatchedSuppressions(settings.nomsg.getUnmatchedGlobalSuppressions(enableUnusedFunctionCheck)); } if (!settings.checkConfiguration) { cppcheck.tooManyConfigsError("",0U); if (settings.isEnabled("missingInclude") && (Preprocessor::missingIncludeFlag || Preprocessor::missingSystemIncludeFlag)) { const std::list<ErrorLogger::ErrorMessage::FileLocation> callStack; ErrorLogger::ErrorMessage msg(callStack, Severity::information, "Cppcheck cannot find all the include files (use --check-config for details)\n" "Cppcheck cannot find all the include files. Cppcheck can check the code without the " "include files found. But the results will probably be more accurate if all the include " "files are found. Please check your project's include directories and add all of them " "as include directories for Cppcheck. To see what files Cppcheck cannot find use " "--check-config.", Preprocessor::missingIncludeFlag ? "missingInclude" : "missingIncludeSystem", false); reportInfo(msg); } } if (settings._xml) { reportErr(ErrorLogger::ErrorMessage::getXMLFooter(settings._xml_version)); } _settings = 0; if (returnValue) return settings._exitCode; else return 0; }