Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 37 additions & 28 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,36 +255,9 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedF
int CppCheckExecutor::check_internal(CppCheck& cppcheck)
{
Settings& settings = cppcheck.settings();
const bool std = tryLoadLibrary(settings.library, settings.exename, "std.cfg");

auto failed_lib = std::find_if(settings.libraries.begin(), settings.libraries.end(), [&](const std::string& lib) {
return !tryLoadLibrary(settings.library, settings.exename, lib.c_str());
});
if (failed_lib != settings.libraries.end()) {
const std::string msg("Failed to load the library " + *failed_lib);
const std::list<ErrorMessage::FileLocation> callstack;
ErrorMessage errmsg(callstack, emptyString, Severity::information, msg, "failedToLoadCfg", Certainty::normal);
reportErr(errmsg);
if (!loadLibraries(settings))
return EXIT_FAILURE;
}

if (!std) {
const std::list<ErrorMessage::FileLocation> callstack;
const std::string msg("Failed to load std.cfg. Your Cppcheck installation is broken, please re-install.");
#ifdef FILESDIR
const std::string details("The Cppcheck binary was compiled with FILESDIR set to \""
FILESDIR "\" and will therefore search for "
"std.cfg in " FILESDIR "/cfg.");
#else
const std::string cfgfolder(Path::fromNativeSeparators(Path::getPathFromFilename(settings.exename)) + "cfg");
const std::string details("The Cppcheck binary was compiled without FILESDIR set. Either the "
"std.cfg should be available in " + cfgfolder + " or the FILESDIR "
"should be configured.");
#endif
ErrorMessage errmsg(callstack, emptyString, Severity::information, msg+" "+details, "failedToLoadCfg", Certainty::normal);
reportErr(errmsg);
return EXIT_FAILURE;
}

if (settings.reportProgress)
mLatestProgressOutputTime = std::time(nullptr);
Expand Down Expand Up @@ -341,6 +314,42 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck)
return 0;
}

bool CppCheckExecutor::loadLibraries(Settings& settings)
{
const bool std = tryLoadLibrary(settings.library, settings.exename, "std.cfg");

const auto failed_lib = std::find_if(settings.libraries.begin(), settings.libraries.end(), [&](const std::string& lib) {
return !tryLoadLibrary(settings.library, settings.exename, lib.c_str());
});
if (failed_lib != settings.libraries.end()) {
const std::string msg("Failed to load the library " + *failed_lib);
const std::list<ErrorMessage::FileLocation> callstack;
ErrorMessage errmsg(callstack, emptyString, Severity::information, msg, "failedToLoadCfg", Certainty::normal);
reportErr(errmsg);
return false;
}

if (!std) {
const std::list<ErrorMessage::FileLocation> callstack;
const std::string msg("Failed to load std.cfg. Your Cppcheck installation is broken, please re-install.");
#ifdef FILESDIR
const std::string details("The Cppcheck binary was compiled with FILESDIR set to \""
FILESDIR "\" and will therefore search for "
"std.cfg in " FILESDIR "/cfg.");
#else
const std::string cfgfolder(Path::fromNativeSeparators(Path::getPathFromFilename(settings.exename)) + "cfg");
const std::string details("The Cppcheck binary was compiled without FILESDIR set. Either the "
"std.cfg should be available in " + cfgfolder + " or the FILESDIR "
"should be configured.");
#endif
ErrorMessage errmsg(callstack, emptyString, Severity::information, msg+" "+details, "failedToLoadCfg", Certainty::normal);
reportErr(errmsg);
return false;
}

return true;
}

#ifdef _WIN32
// fix trac ticket #439 'Cppcheck reports wrong filename for filenames containing 8-bit ASCII'
static inline std::string ansiToOEM(const std::string &msg, bool doConvert)
Expand Down
7 changes: 7 additions & 0 deletions cli/cppcheckexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ class CppCheckExecutor : public ErrorLogger {
*/
int check_internal(CppCheck& cppcheck);

/**
* @brief Load libraries
* @param settings Settings
* @return Returns true if successful
*/
bool loadLibraries(Settings& settings);

/**
* Pointer to current settings; set while check() is running for reportError().
*/
Expand Down