Skip to content
Draft
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ $(libcppdir)/cppcheck.o: lib/cppcheck.cpp externals/picojson/picojson.h external
$(libcppdir)/ctu.o: lib/ctu.cpp externals/tinyxml2/tinyxml2.h lib/astutils.h lib/check.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.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)/ctu.cpp

$(libcppdir)/errorlogger.o: lib/errorlogger.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/regex.h lib/settings.h lib/smallvector.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vfvalue.h lib/xml.h
$(libcppdir)/errorlogger.o: lib/errorlogger.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/regex.h lib/settings.h lib/smallvector.h lib/standards.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vfvalue.h lib/xml.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/errorlogger.cpp

$(libcppdir)/errortypes.o: lib/errortypes.cpp lib/config.h lib/errortypes.h lib/utils.h
Expand Down Expand Up @@ -785,7 +785,7 @@ test/testconstructors.o: test/testconstructors.cpp lib/addoninfo.h lib/check.h l
test/testcppcheck.o: test/testcppcheck.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/preprocessor.h lib/regex.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h test/redirect.h
$(CXX) ${INCLUDE_FOR_TEST} ${CFLAGS_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testcppcheck.cpp

test/testerrorlogger.o: test/testerrorlogger.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/regex.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/xml.h test/fixture.h test/helpers.h
test/testerrorlogger.o: test/testerrorlogger.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/regex.h lib/settings.h lib/standards.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/xml.h test/fixture.h test/helpers.h
$(CXX) ${INCLUDE_FOR_TEST} ${CFLAGS_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testerrorlogger.cpp

test/testexceptionsafety.o: test/testexceptionsafety.cpp lib/addoninfo.h lib/check.h lib/checkers.h lib/checkexceptionsafety.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/regex.h lib/settings.h lib/standards.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h
Expand Down
6 changes: 3 additions & 3 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ static std::vector<ErrorMessage> getUnmatchedSuppressions(const std::list<Suppre
for (const SuppressionList::Suppression &s2 : unmatched) {
if (s2.errorId == "unmatchedSuppression") { // TODO: handle unmatchedPolyspaceSuppression?
if ((s2.fileName.empty() || s2.fileName == "*" || s2.fileName == s.fileName) &&
(s2.lineNumber == SuppressionList::Suppression::NO_LINE || s2.lineNumber == s.lineNumber)) {
(s2.lineNumber == 0 || s2.lineNumber == s.lineNumber)) {
suppressed = true;
break;
}
Expand All @@ -329,7 +329,7 @@ static std::vector<ErrorMessage> getUnmatchedSuppressions(const std::list<Suppre

std::list<ErrorMessage::FileLocation> callStack;
if (!s.fileName.empty()) {
callStack.emplace_back(s.fileName, s.lineNumber == -1 ? 0 : s.lineNumber, s.column); // TODO: get rid of s.lineNumber == -1 hack
callStack.emplace_back(s.fileName, s.lineNumber, s.column);
}
const std::string unmatchedSuppressionId = s.isPolyspace ? "unmatchedPolyspaceSuppression" : "unmatchedSuppression";
errors.emplace_back(std::move(callStack), "", Severity::information, "Unmatched suppression: " + s.errorId, unmatchedSuppressionId, Certainty::normal);
Expand All @@ -346,7 +346,7 @@ bool CppCheckExecutor::reportUnmatchedSuppressions(const Settings &settings, con
auto suppr = suppressions.getSuppressions();
if (std::any_of(suppr.cbegin(), suppr.cend(), [](const SuppressionList::Suppression& s) {
// TODO: handle unmatchedPolyspaceSuppression?
return s.errorId == "unmatchedSuppression" && (s.fileName.empty() || s.fileName == "*") && s.lineNumber == SuppressionList::Suppression::NO_LINE;
return s.errorId == "unmatchedSuppression" && (s.fileName.empty() || s.fileName == "*") && s.lineNumber == 0;
}))
return false;

Expand Down
3 changes: 2 additions & 1 deletion gui/projectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ void ProjectFile::readSuppressions(QXmlStreamReader &reader)
if (reader.attributes().hasAttribute(QString(),"fileName"))
suppression.fileName = reader.attributes().value(QString(),"fileName").toString().toStdString();
if (reader.attributes().hasAttribute(QString(),"lineNumber"))
suppression.lineNumber = reader.attributes().value(QString(),"lineNumber").toInt();
suppression.lineNumber = reader.attributes().value(QString(),"lineNumber").toUInt();
if (reader.attributes().hasAttribute(QString(),"symbolName"))
suppression.symbolName = reader.attributes().value(QString(),"symbolName").toString().toStdString();
if (reader.attributes().hasAttribute(QString(),"hash"))
Expand Down Expand Up @@ -948,6 +948,7 @@ bool ProjectFile::write(const QString &filename)
CppcheckXml::LibraryElementName);

if (!mSuppressions.isEmpty()) {
// TODO: merge/align with SuppressionList::dump()?
xmlWriter.writeStartElement(CppcheckXml::SuppressionsElementName);
for (const SuppressionList::Suppression &suppression : utils::as_const(mSuppressions)) {
xmlWriter.writeStartElement(CppcheckXml::SuppressionElementName);
Expand Down
4 changes: 3 additions & 1 deletion gui/projectfiledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,17 @@ static const std::array<Platform::Type, 6> builtinPlatforms = {
Platform::Type::Unix64
};

// TODO: use SuppressionList::Suppression::toString() instead?
static std::string suppressionAsText(const SuppressionList::Suppression& s)
{
std::string ret;
if (!s.errorId.empty())
ret = s.errorId;
if (!s.fileName.empty())
ret += " fileName=" + s.fileName;
if (s.lineNumber != SuppressionList::Suppression::NO_LINE)
if (s.lineNumber != 0)
ret += " lineNumber=" + std::to_string(s.lineNumber);
// do not include column as suppressions are only line-based
if (!s.symbolName.empty())
ret += " symbolName=" + s.symbolName;
if (s.hash > 0)
Expand Down
11 changes: 4 additions & 7 deletions lib/errorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "cppcheck.h"
#include "path.h"
#include "settings.h"
#include "suppressions.h"
#include "token.h"
#include "tokenlist.h"
#include "utils.h"
Expand Down Expand Up @@ -766,13 +765,11 @@ std::string ErrorMessage::FileLocation::stringify(bool addcolumn) const
std::string str;
str += '[';
str += Path::toNativeSeparators(mFileName);
if (line != SuppressionList::Suppression::NO_LINE) { // TODO: should not depend on Suppression
str += ':';
str += std::to_string(line);
if (addcolumn) {
str += ':';
str += std::to_string(line);
if (addcolumn) {
str += ':';
str += std::to_string(column);
}
str += std::to_string(column);
}
str += ']';
return str;
Expand Down
2 changes: 1 addition & 1 deletion lib/errorlogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CPPCHECKLIB ErrorMessage {
std::string stringify(bool addcolumn = false) const;

unsigned int fileIndex;
int line; // negative value means "no line"
int line; // TODO: should be unsigned
unsigned int column;

const std::string& getinfo() const {
Expand Down
2 changes: 1 addition & 1 deletion lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings &setti
s.fileName = empty_if_null(child->Attribute("fileName"));
if (!s.fileName.empty())
s.fileName = joinRelativePath(path, s.fileName);
s.lineNumber = child->IntAttribute("lineNumber", SuppressionList::Suppression::NO_LINE); // TODO: should not depend on Suppression
s.lineNumber = child->UnsignedAttribute("lineNumber", 0);
s.symbolName = empty_if_null(child->Attribute("symbolName"));
s.hash = strToInt<std::size_t>(default_if_null(child->Attribute("hash"), "0"));
suppressions.push_back(std::move(s));
Expand Down
22 changes: 11 additions & 11 deletions lib/suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ SuppressionList::ErrorMessage SuppressionList::ErrorMessage::fromErrorMessage(co
ret.lineNumber = msg.callStack.back().line;
} else {
ret.setFileName(msg.file0);
ret.lineNumber = SuppressionList::Suppression::NO_LINE;
ret.lineNumber = 0;
}
ret.certainty = msg.certainty;
ret.symbolNames = msg.symbolNames();
Expand Down Expand Up @@ -132,7 +132,7 @@ std::string SuppressionList::parseXmlFile(const char *filename)
else if (std::strcmp(name, "fileName") == 0)
s.fileName = Path::simplifyPath(text);
else if (std::strcmp(name, "lineNumber") == 0)
s.lineNumber = strToInt<int>(text);
s.lineNumber = strToInt<unsigned int>(text);
else if (std::strcmp(name, "symbolName") == 0)
s.symbolName = text;
else if (*text && std::strcmp(name, "hash") == 0)
Expand Down Expand Up @@ -247,7 +247,7 @@ SuppressionList::Suppression SuppressionList::parseLine(std::string line)
throw std::runtime_error("filename is missing");

try {
suppression.lineNumber = strToInt<int>(line_s);
suppression.lineNumber = strToInt<unsigned int>(line_s);
} catch (const std::runtime_error& e) {
throw std::runtime_error(std::string("invalid line number (") + e.what() + ")");
}
Expand Down Expand Up @@ -415,7 +415,7 @@ SuppressionList::Suppression::Result SuppressionList::Suppression::isSuppressed(
if (!errorId.empty() && !matchglob(errorId, errmsg.errorId))
return Result::Checked;
} else {
if ((SuppressionList::Type::unique == type) && (lineNumber != NO_LINE) && (lineNumber != errmsg.lineNumber)) {
if ((SuppressionList::Type::unique == type) && (lineNumber != 0) && (lineNumber != errmsg.lineNumber)) {
if (!thisAndNextLine || lineNumber + 1 != errmsg.lineNumber)
return Result::None;
}
Expand Down Expand Up @@ -524,15 +524,15 @@ void SuppressionList::dump(std::ostream & out, const std::string& filePath) cons
out << " errorId=\"" << ErrorLogger::toxml(suppression.errorId) << '"';
if (!suppression.fileName.empty())
out << " fileName=\"" << ErrorLogger::toxml(suppression.fileName) << '"';
if (suppression.lineNumber != Suppression::NO_LINE)
if (suppression.lineNumber != 0)
out << " lineNumber=\"" << suppression.lineNumber << '"';
if (!suppression.symbolName.empty())
out << " symbolName=\"" << ErrorLogger::toxml(suppression.symbolName) << '\"';
if (suppression.hash > 0)
out << " hash=\"" << suppression.hash << '\"';
if (suppression.lineBegin != Suppression::NO_LINE)
if (suppression.lineBegin != 0)
out << " lineBegin=\"" << suppression.lineBegin << '"';
if (suppression.lineEnd != Suppression::NO_LINE)
if (suppression.lineEnd != 0)
out << " lineEnd=\"" << suppression.lineEnd << '"';
if (suppression.type == SuppressionList::Type::file)
out << " type=\"file\"";
Expand Down Expand Up @@ -565,7 +565,7 @@ std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedLocalSuppre
continue;
if (s.matched)
continue;
if ((s.lineNumber != Suppression::NO_LINE) && !s.checked)
if ((s.lineNumber != 0) && !s.checked)
continue;
if (s.type == SuppressionList::Type::macro)
continue;
Expand Down Expand Up @@ -631,7 +631,7 @@ std::list<SuppressionList::Suppression> SuppressionList::getSuppressions() const
void SuppressionList::markUnmatchedInlineSuppressionsAsChecked(const TokenList &tokenlist) {
std::lock_guard<std::mutex> lg(mSuppressionsSync);

int currLineNr = -1;
unsigned int currLineNr = 0;
int currFileIdx = -1;
for (const Token *tok = tokenlist.front(); tok; tok = tok->next()) {
if (currFileIdx != tok->fileIndex() || currLineNr != tok->linenr()) {
Expand Down Expand Up @@ -661,7 +661,7 @@ std::string SuppressionList::Suppression::toString() const
if (!fileName.empty()) {
s += ':';
s += fileName;
if (lineNumber != -1) {
if (lineNumber != 0) {
s += ':';
s += std::to_string(lineNumber);
}
Expand Down Expand Up @@ -746,7 +746,7 @@ polyspace::CommentKind polyspace::Parser::parseKind(const std::string& comment,
}


std::list<SuppressionList::Suppression> polyspace::Parser::parse(const std::string &comment, int line, const std::string &filename) const
std::list<SuppressionList::Suppression> polyspace::Parser::parse(const std::string &comment, unsigned int line, const std::string &filename) const
{
// Syntax for a polyspace suppression:
// https://se.mathworks.com/help/bugfinder/ug/annotate-hide-known-acceptable-polyspace-results-web-browser.html
Expand Down
12 changes: 5 additions & 7 deletions lib/suppressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CPPCHECKLIB SuppressionList {

struct CPPCHECKLIB Suppression {
Suppression() = default;
Suppression(std::string id, std::string file, int line=NO_LINE) : errorId(std::move(id)), fileName(std::move(file)), lineNumber(line) {}
Suppression(std::string id, std::string file, unsigned int line=0) : errorId(std::move(id)), fileName(std::move(file)), lineNumber(line) {}

bool operator<(const Suppression &other) const {
if (errorId != other.errorId)
Expand Down Expand Up @@ -153,9 +153,9 @@ class CPPCHECKLIB SuppressionList {
std::string extraComment;
// TODO: use simplecpp::Location?
int fileIndex{};
int lineNumber = NO_LINE; // TODO: needs to be unsigned
int lineBegin = NO_LINE;
int lineEnd = NO_LINE;
unsigned int lineNumber{};
unsigned int lineBegin{};
unsigned int lineEnd {};
int column{};
Type type = Type::unique;
std::string symbolName;
Expand All @@ -166,8 +166,6 @@ class CPPCHECKLIB SuppressionList {
bool checked{}; /** This suppression applied to code which was being analyzed but did not match the error in an isSuppressed() call */
bool isInline{};
bool isPolyspace{};

enum : std::int8_t { NO_LINE = -1 };
};

/**
Expand Down Expand Up @@ -312,7 +310,7 @@ namespace polyspace {
Parser() = delete;
explicit Parser(const Settings &settings);

std::list<SuppressionList::Suppression> parse(const std::string &comment, int line, const std::string &filename) const;
std::list<SuppressionList::Suppression> parse(const std::string &comment, unsigned int line, const std::string &filename) const;

static int parseRange(const std::string& comment, std::string::size_type& pos);
static std::vector<std::pair<std::string, std::string>> parseFamilyRules(const std::string& comment, std::string::size_type& pos);
Expand Down
2 changes: 1 addition & 1 deletion oss-fuzz/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ $(libcppdir)/cppcheck.o: ../lib/cppcheck.cpp ../externals/picojson/picojson.h ..
$(libcppdir)/ctu.o: ../lib/ctu.cpp ../externals/tinyxml2/tinyxml2.h ../lib/astutils.h ../lib/check.h ../lib/config.h ../lib/ctu.h ../lib/errorlogger.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/path.h ../lib/smallvector.h ../lib/sourcelocation.h ../lib/standards.h ../lib/symboldatabase.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)/ctu.cpp

$(libcppdir)/errorlogger.o: ../lib/errorlogger.cpp ../externals/tinyxml2/tinyxml2.h ../lib/addoninfo.h ../lib/check.h ../lib/checkers.h ../lib/color.h ../lib/config.h ../lib/cppcheck.h ../lib/errorlogger.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/regex.h ../lib/settings.h ../lib/smallvector.h ../lib/standards.h ../lib/suppressions.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h ../lib/xml.h
$(libcppdir)/errorlogger.o: ../lib/errorlogger.cpp ../externals/tinyxml2/tinyxml2.h ../lib/addoninfo.h ../lib/check.h ../lib/checkers.h ../lib/color.h ../lib/config.h ../lib/cppcheck.h ../lib/errorlogger.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/regex.h ../lib/settings.h ../lib/smallvector.h ../lib/standards.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h ../lib/xml.h
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/errorlogger.cpp

$(libcppdir)/errortypes.o: ../lib/errortypes.cpp ../lib/config.h ../lib/errortypes.h ../lib/utils.h
Expand Down
9 changes: 4 additions & 5 deletions test/testerrorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "errortypes.h"
#include "fixture.h"
#include "helpers.h"
#include "suppressions.h"

#include <list>
#include <string>
Expand Down Expand Up @@ -237,14 +236,14 @@ class TestErrorLogger : public TestFixture {
}

void FileLocationSetFile2() const {
ErrorMessage::FileLocation loc("foo1.cpp", SuppressionList::Suppression::NO_LINE, 0); // TODO: should not depend on Suppression
ErrorMessage::FileLocation loc("foo1.cpp", 0, 0);
loc.setfile("foo.cpp");
ASSERT_EQUALS("foo1.cpp", loc.getOrigFile(false));
ASSERT_EQUALS("foo.cpp", loc.getfile(false));
ASSERT_EQUALS(SuppressionList::Suppression::NO_LINE, loc.line);
ASSERT_EQUALS(0, loc.line);
ASSERT_EQUALS(0, loc.column);
ASSERT_EQUALS("[foo.cpp]", loc.stringify(false));
ASSERT_EQUALS("[foo.cpp]", loc.stringify(true));
ASSERT_EQUALS("[foo.cpp:0]", loc.stringify(false));
ASSERT_EQUALS("[foo.cpp:0:0]", loc.stringify(true));
}

void ErrorMessageConstruct() const {
Expand Down
Loading