Skip to content

Commit

Permalink
even more FileWithDetails usage
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Jun 11, 2024
1 parent adb2260 commit 8fe6016
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 71 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ $(libcppdir)/settings.o: lib/settings.cpp externals/picojson/picojson.h lib/addo
$(libcppdir)/summaries.o: lib/summaries.cpp lib/addoninfo.h lib/analyzerinfo.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/summaries.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/summaries.cpp

$(libcppdir)/suppressions.o: lib/suppressions.cpp externals/tinyxml2/tinyxml2.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/mathlib.h lib/path.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h lib/xml.h
$(libcppdir)/suppressions.o: lib/suppressions.cpp externals/tinyxml2/tinyxml2.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/mathlib.h lib/path.h lib/platform.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h lib/xml.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/suppressions.cpp

$(libcppdir)/templatesimplifier.o: lib/templatesimplifier.cpp lib/addoninfo.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
Expand Down
4 changes: 2 additions & 2 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,12 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, const Suppre

for (std::list<FileWithDetails>::const_iterator i = files.cbegin(); i != files.cend(); ++i) {
err |= SuppressionList::reportUnmatchedSuppressions(
suppressions.getUnmatchedLocalSuppressions(i->path(), unusedFunctionCheckEnabled), errorLogger);
suppressions.getUnmatchedLocalSuppressions(*i, unusedFunctionCheckEnabled), errorLogger);
}

for (std::list<FileSettings>::const_iterator i = fileSettings.cbegin(); i != fileSettings.cend(); ++i) {
err |= SuppressionList::reportUnmatchedSuppressions(
suppressions.getUnmatchedLocalSuppressions(i->filename(), unusedFunctionCheckEnabled), errorLogger);
suppressions.getUnmatchedLocalSuppressions(i->file, unusedFunctionCheckEnabled), errorLogger);
}
}
err |= SuppressionList::reportUnmatchedSuppressions(suppressions.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled), errorLogger);
Expand Down
105 changes: 54 additions & 51 deletions lib/cppcheck.cpp

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions lib/cppcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ class CPPCHECKLIB CppCheck : ErrorLogger {

/**
* @brief Check a file using stream
* @param filename file name
* @param file the file
* @param cfgname cfg name
* @param fileStream stream the file content can be read from
* @return number of errors found
*/
unsigned int checkFile(const std::string& filename, const std::string &cfgname, std::istream* fileStream = nullptr);
unsigned int checkFile(const FileWithDetails& file, const std::string &cfgname, std::istream* fileStream = nullptr);

/**
* @brief Check normal tokens
Expand All @@ -189,7 +189,7 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
* Execute addons
*/
void executeAddons(const std::vector<std::string>& files, const std::string& file0);
void executeAddons(const std::string &dumpFile, const std::string& file0);
void executeAddons(const std::string &dumpFile, const FileWithDetails& file);

/**
* Execute addons
Expand All @@ -205,7 +205,7 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
void executeRules(const std::string &tokenlist, const TokenList &list);
#endif

unsigned int checkClang(const std::string &path);
unsigned int checkClang(const FileWithDetails &file);

/**
* @brief Errors and warnings are directed here.
Expand Down
14 changes: 10 additions & 4 deletions lib/filesettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <list>
#include <set>
#include <stdexcept>
#include <string>
#include <utility>

Expand All @@ -37,17 +38,21 @@ class FileWithDetails

FileWithDetails(std::string path, std::size_t size)
: mPath(std::move(path))
, mPathSimplified(Path::simplifyPath(mPath))
, mSize(size)
{}
{
if (mPath.empty())
throw std::runtime_error("empty path specified");
}

const std::string& path() const
{
return mPath;
}

std::string spath() const
const std::string& spath() const
{
return Path::simplifyPath(mPath);
return mPathSimplified;
}

std::size_t size() const
Expand All @@ -56,6 +61,7 @@ class FileWithDetails
}
private:
std::string mPath;
std::string mPathSimplified;
std::size_t mSize;
};

Expand All @@ -75,7 +81,7 @@ struct CPPCHECKLIB FileSettings {
{
return file.path();
}
std::string sfilename() const
const std::string& sfilename() const
{
return file.spath();
}
Expand Down
6 changes: 3 additions & 3 deletions lib/suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "errorlogger.h"
#include "errortypes.h"
#include "filesettings.h"
#include "path.h"
#include "utils.h"
#include "token.h"
Expand Down Expand Up @@ -475,9 +476,8 @@ void SuppressionList::dump(std::ostream & out) const
out << " </suppressions>" << std::endl;
}

std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedLocalSuppressions(const std::string &file, const bool unusedFunctionChecking) const
std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedLocalSuppressions(const FileWithDetails &file, const bool unusedFunctionChecking) const
{
std::string tmpFile = Path::simplifyPath(file);
std::list<Suppression> result;
for (const Suppression &s : mSuppressions) {
if (s.matched || ((s.lineNumber != Suppression::NO_LINE) && !s.checked))
Expand All @@ -490,7 +490,7 @@ std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedLocalSuppre
continue;
if (!unusedFunctionChecking && s.errorId == ID_UNUSEDFUNCTION)
continue;
if (tmpFile.empty() || !s.isLocal() || s.fileName != tmpFile)
if (!s.isLocal() || s.fileName != file.spath())
continue;
result.push_back(s);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/suppressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Tokenizer;
class ErrorMessage;
class ErrorLogger;
enum class Certainty;
class FileWithDetails;

/** @brief class for handling suppressions */
class CPPCHECKLIB SuppressionList {
Expand Down Expand Up @@ -227,7 +228,7 @@ class CPPCHECKLIB SuppressionList {
* @brief Returns list of unmatched local (per-file) suppressions.
* @return list of unmatched suppressions
*/
std::list<Suppression> getUnmatchedLocalSuppressions(const std::string &file, const bool unusedFunctionChecking) const;
std::list<Suppression> getUnmatchedLocalSuppressions(const FileWithDetails &file, const bool unusedFunctionChecking) const;

/**
* @brief Returns list of unmatched global (glob pattern) suppressions.
Expand Down
2 changes: 1 addition & 1 deletion oss-fuzz/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ $(libcppdir)/settings.o: ../lib/settings.cpp ../externals/picojson/picojson.h ..
$(libcppdir)/summaries.o: ../lib/summaries.cpp ../lib/addoninfo.h ../lib/analyzerinfo.h ../lib/config.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/platform.h ../lib/settings.h ../lib/sourcelocation.h ../lib/standards.h ../lib/summaries.h ../lib/suppressions.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenize.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/summaries.cpp

$(libcppdir)/suppressions.o: ../lib/suppressions.cpp ../externals/tinyxml2/tinyxml2.h ../lib/color.h ../lib/config.h ../lib/errorlogger.h ../lib/errortypes.h ../lib/mathlib.h ../lib/path.h ../lib/standards.h ../lib/suppressions.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenize.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h ../lib/xml.h
$(libcppdir)/suppressions.o: ../lib/suppressions.cpp ../externals/tinyxml2/tinyxml2.h ../lib/color.h ../lib/config.h ../lib/errorlogger.h ../lib/errortypes.h ../lib/filesettings.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/standards.h ../lib/suppressions.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenize.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h ../lib/xml.h
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/suppressions.cpp

$(libcppdir)/templatesimplifier.o: ../lib/templatesimplifier.cpp ../lib/addoninfo.h ../lib/color.h ../lib/config.h ../lib/errorlogger.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/platform.h ../lib/settings.h ../lib/standards.h ../lib/suppressions.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenize.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h
Expand Down
8 changes: 4 additions & 4 deletions test/testsuppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1194,18 +1194,18 @@ class TestSuppressions : public TestFixture {
SuppressionList::Suppression suppression("unusedFunction", "test.c", 3);
suppression.checked = true; // have to do this because fixes for #5704
ASSERT_EQUALS("", suppressions.addSuppression(std::move(suppression)));
ASSERT_EQUALS(true, !suppressions.getUnmatchedLocalSuppressions("test.c", true).empty());
ASSERT_EQUALS(true, !suppressions.getUnmatchedLocalSuppressions(FileWithDetails("test.c"), true).empty());
ASSERT_EQUALS(false, !suppressions.getUnmatchedGlobalSuppressions(true).empty());
ASSERT_EQUALS(false, !suppressions.getUnmatchedLocalSuppressions("test.c", false).empty());
ASSERT_EQUALS(false, !suppressions.getUnmatchedLocalSuppressions(FileWithDetails("test.c"), false).empty());
ASSERT_EQUALS(false, !suppressions.getUnmatchedGlobalSuppressions(false).empty());
}

void globalsuppress_unusedFunction() const { // #4946 - wrong report of "unmatchedSuppression" for "unusedFunction"
SuppressionList suppressions;
ASSERT_EQUALS("", suppressions.addSuppressionLine("unusedFunction:*"));
ASSERT_EQUALS(false, !suppressions.getUnmatchedLocalSuppressions("test.c", true).empty());
ASSERT_EQUALS(false, !suppressions.getUnmatchedLocalSuppressions(FileWithDetails("test.c"), true).empty());
ASSERT_EQUALS(true, !suppressions.getUnmatchedGlobalSuppressions(true).empty());
ASSERT_EQUALS(false, !suppressions.getUnmatchedLocalSuppressions("test.c", false).empty());
ASSERT_EQUALS(false, !suppressions.getUnmatchedLocalSuppressions(FileWithDetails("test.c"), false).empty());
ASSERT_EQUALS(false, !suppressions.getUnmatchedGlobalSuppressions(false).empty());
}

Expand Down

0 comments on commit 8fe6016

Please sign in to comment.