Skip to content

Commit

Permalink
Add fix
Browse files Browse the repository at this point in the history
  • Loading branch information
olabetskyi committed Aug 30, 2024
1 parent 018ebc3 commit 0ef5641
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
32 changes: 7 additions & 25 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,23 +580,16 @@ unsigned int CppCheck::check(const FileWithDetails &file, const std::string &con

unsigned int CppCheck::check(const FileSettings &fs)
{
<<<<<<< HEAD
<<<<<<< HEAD
// TODO: move to constructor when CppCheck no longer owns the settings
if (mSettings.checks.isEnabled(Checks::unusedFunction) && !mUnusedFunctionsCheck)
mUnusedFunctionsCheck.reset(new CheckUnusedFunctions());

=======
if (!Path::isFile(fs.filename)) {
std::string fixedpath = Path::simplifyPath(fs.filename);
fixedpath = Path::toNativeSeparators(fixedpath);
const std::string errorMsg("File " + fixedpath + " does not exists. Skipping file.");
fileNotFoundError(fs.filename, errorMsg);
return 0;
}
>>>>>>> 8f585fe73 (Fix)
=======
>>>>>>> 74a6847dd (Remodel)
CppCheck temp(mErrorLogger, mUseGlobalSuppressions, mExecuteCommand);
temp.mSettings = mSettings;
if (!temp.mSettings.userDefines.empty())
Expand Down Expand Up @@ -714,19 +707,16 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
std::string locfile = Path::fromNativeSeparators(output.location.file());
if (mSettings.relativePaths)
locfile = Path::getRelativePath(locfile, mSettings.basePaths);

ErrorMessage::FileLocation loc1(locfile, output.location.line, output.location.col);

ErrorMessage errmsg({std::move(loc1)},
"", // TODO: is this correct?
Severity::error,
output.msg,
"syntaxError",
Certainty::normal);
if(output.type == simplecpp::Output::Type::FILE_NOT_FOUND){
const std::string fixedpath = Path::toNativeSeparators(file);
const std::string errorMsg("File " + fixedpath + " does not exists. Skipping file.");
fileNotFoundError(file, errorMsg);

reportErr(ErrorMessage(std::list<ErrorMessage::FileLocation> (),
emptyString,
Severity::error,
errorMsg,
"fileNotFound",
Certainty::normal));
}
else{
reportErr(makeError(file, output.location.line, output.location.col, output.msg, "syntaxError"));
Expand Down Expand Up @@ -1057,7 +1047,6 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
return mExitCode;
}

<<<<<<< HEAD
static ErrorMessage makeError(const std::string &filename, const std::string &msg, const std::string &id)
{
const std::string fullmsg("Bailing out from analysis: " + msg);
Expand All @@ -1073,19 +1062,12 @@ static ErrorMessage makeError(const std::string &filename, const std::string &ms
Certainty::normal);
}

=======
>>>>>>> 74a6847dd (Remodel)
// TODO: replace with ErrorMessage::fromInternalError()
void CppCheck::internalError(const std::string &filename, const std::string &msg)
{
mErrorLogger.reportErr(makeError(filename, 0, 0U, "Bailing out from analysis:" + msg, "internalError"));
}

void CppCheck::fileNotFoundError(const std::string &filename, const std::string &msg)
{
mErrorLogger.reportErr(makeError(filename, 0, 0U, msg, "fileNotFound"));
}

//---------------------------------------------------------------------------
// CppCheck - A function that checks a normal token list
//---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion test/cli/more-projects_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,4 +870,4 @@ def test_project_missing_files():
filename = os.path.join('invalid-project', 'main.c')
ret, _, stderr = cppcheck(['--template=cppcheck1', '--project=' + os.path.join('invalid-project', 'invalid-project.vcxproj')])
assert ret == 0
assert stderr == '[{}:0]: (error) File {} does not exists. Skipping file.\n'.format(filename, filename)
assert stderr == ': (error) File {} does not exists. Skipping file.\n'.format(filename)
3 changes: 2 additions & 1 deletion test/testcppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ class TestCppcheck : public TestFixture {
{
ErrorLogger2 errorLogger;
CppCheck cppcheck(errorLogger, false, {});
ASSERT_EQUALS(0, cppcheck.check("NotAFile"));
ASSERT_EQUALS(1, cppcheck.check("NotAFile"));

ASSERT_EQUALS(1, errorLogger.ids.size());
ASSERT_EQUALS("fileNotFound", *errorLogger.ids.cbegin());
ASSERT_EQUALS("File NotAFile does not exists. Skipping file.", errorLogger.errmsgs.cbegin()->shortMessage());
}

void checkWithFS() const
Expand Down

0 comments on commit 0ef5641

Please sign in to comment.