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
32 changes: 14 additions & 18 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#endif

#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib> // EXIT_SUCCESS and EXIT_FAILURE
#include <functional>
Expand All @@ -66,6 +67,8 @@
#include <windows.h>
#endif

// TODO: do not directly write to stdout


/*static*/ FILE* CppCheckExecutor::mExceptionOutput = stdout;

Expand Down Expand Up @@ -319,21 +322,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck)

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;
if (!tryLoadLibrary(settings.library, settings.exename, "std.cfg")) {
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 \""
Expand All @@ -345,12 +334,17 @@ bool CppCheckExecutor::loadLibraries(Settings& settings)
"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);
std::cout << msg << " " << details << std::endl;
return false;
}

return true;
bool result = true;
for (const auto& lib : settings.libraries) {
if (!tryLoadLibrary(settings.library, settings.exename, lib.c_str())) {
result = false;
}
}
return result;
}

#ifdef _WIN32
Expand Down Expand Up @@ -424,6 +418,8 @@ void CppCheckExecutor::reportErr(const ErrorMessage &msg)
return;
}

assert(mSettings != nullptr);

// Alert only about unique errors
if (!mShownErrors.insert(msg.toString(mSettings->verbose)).second)
return;
Expand Down
13 changes: 12 additions & 1 deletion test/cli/test-other.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,15 @@ def test_missing_include_inline_suppr(tmpdir):
args = ['--enable=missingInclude', '--inline-suppr', test_file]

_, _, stderr = cppcheck(args)
assert stderr == ''
assert stderr == ''

def test_invalid_library(tmpdir):
args = ['--library=none', '--library=posix', '--library=none2', '--platform=native', 'file.c']

exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 1
assert (stdout == "cppcheck: Failed to load library configuration file 'none'. File not found\n"
"cppcheck: Failed to load library configuration file 'none2'. File not found\n")
assert stderr == ""

# TODO: test missing std.cfg