Skip to content

Commit

Permalink
Add fix
Browse files Browse the repository at this point in the history
  • Loading branch information
olabetskyi committed Feb 2, 2024
1 parent 74a6847 commit 623cc0d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
22 changes: 7 additions & 15 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,19 +674,16 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
if (mSettings.relativePaths)
file = Path::getRelativePath(file, mSettings.basePaths);

const ErrorMessage::FileLocation loc1(file, output.location.line, output.location.col);
std::list<ErrorMessage::FileLocation> callstack(1, loc1);

ErrorMessage errmsg(callstack,
"",
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 @@ -1059,11 +1056,6 @@ 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 raw 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 @@ -643,4 +643,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 @@ -113,10 +113,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 623cc0d

Please sign in to comment.