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
2 changes: 1 addition & 1 deletion lib/errorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ std::string ErrorLogger::ErrorMessage::FileLocation::stringify() const
{
std::ostringstream oss;
oss << '[' << Path::toNativeSeparators(mFileName);
if (line != 0)
if (line != Suppressions::Suppression::NO_LINE)
oss << ':' << line;
oss << ']';
return oss.str();
Expand Down
10 changes: 5 additions & 5 deletions lib/suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ std::string Suppressions::addSuppressionLine(const std::string &line)
std::istringstream istr1(suppression.fileName.substr(pos+1));
istr1 >> suppression.lineNumber;
} catch (...) {
suppression.lineNumber = 0;
suppression.lineNumber = Suppressions::Suppression::NO_LINE;
}

if (suppression.lineNumber > 0) {
if (suppression.lineNumber > Suppressions::Suppression::NO_LINE) {
suppression.fileName.erase(pos);
}
}
Expand Down Expand Up @@ -233,7 +233,7 @@ bool Suppressions::Suppression::isSuppressed(const Suppressions::ErrorMessage &e
return false;
if (!fileName.empty() && !matchglob(fileName, errmsg.getFileName()))
return false;
if (lineNumber > 0 && lineNumber != errmsg.lineNumber)
if (lineNumber > NO_LINE && lineNumber != errmsg.lineNumber)
return false;
if (!symbolName.empty()) {
for (std::string::size_type pos = 0; pos < errmsg.symbolNames.size();) {
Expand Down Expand Up @@ -269,7 +269,7 @@ std::string Suppressions::Suppression::getText() const
ret = errorId;
if (!fileName.empty())
ret += " fileName=" + fileName;
if (lineNumber > 0)
if (lineNumber > NO_LINE)
ret += " lineNumber=" + MathLib::toString(lineNumber);
if (!symbolName.empty())
ret += " symbolName=" + symbolName;
Expand Down Expand Up @@ -312,7 +312,7 @@ void Suppressions::dump(std::ostream & out)
out << " errorId=\"" << ErrorLogger::toxml(suppression.errorId) << '"';
if (!suppression.fileName.empty())
out << " fileName=\"" << ErrorLogger::toxml(suppression.fileName) << '"';
if (suppression.lineNumber > 0)
if (suppression.lineNumber > Suppression::NO_LINE)
out << " lineNumber=\"" << suppression.lineNumber << '"';
if (!suppression.symbolName.empty())
out << " symbolName=\"" << ErrorLogger::toxml(suppression.symbolName) << '\"';
Expand Down
2 changes: 1 addition & 1 deletion lib/suppressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class CPPCHECKLIB Suppressions {
std::string symbolName;
bool matched;

static const int NO_LINE = 0;
enum { NO_LINE = -1 };
};

/**
Expand Down
6 changes: 3 additions & 3 deletions test/testerrorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,15 @@ class TestErrorLogger : public TestFixture {
errout.str("");
suppressions.clear();
suppressions.emplace_back("abc", "a.c", 10U);
suppressions.emplace_back("unmatchedSuppression", "*", 0U);
suppressions.emplace_back("unmatchedSuppression", "*", Suppressions::Suppression::NO_LINE);
reportUnmatchedSuppressions(suppressions);
ASSERT_EQUALS("", errout.str());

// suppress all unmatchedSuppression in a.c
errout.str("");
suppressions.clear();
suppressions.emplace_back("abc", "a.c", 10U);
suppressions.emplace_back("unmatchedSuppression", "a.c", 0U);
suppressions.emplace_back("unmatchedSuppression", "a.c", Suppressions::Suppression::NO_LINE);
reportUnmatchedSuppressions(suppressions);
ASSERT_EQUALS("", errout.str());

Expand All @@ -325,7 +325,7 @@ class TestErrorLogger : public TestFixture {
errout.str("");
suppressions.clear();
suppressions.emplace_back("abc", "a.c", 10U);
suppressions.emplace_back("unmatchedSuppression", "b.c", 0U);
suppressions.emplace_back("unmatchedSuppression", "b.c", Suppressions::Suppression::NO_LINE);
reportUnmatchedSuppressions(suppressions);
ASSERT_EQUALS("[a.c:10]: (information) Unmatched suppression: abc\n", errout.str());

Expand Down
8 changes: 8 additions & 0 deletions test/testsuppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "suppressions.h"
#include "testsuite.h"
#include "threadexecutor.h"
#include "path.h"

#include <cstddef>
#include <list>
Expand All @@ -46,6 +47,7 @@ class TestSuppressions : public TestFixture {
TEST_CASE(suppressionsSettings);
TEST_CASE(suppressionsMultiFile);
TEST_CASE(suppressionsPathSeparator);
TEST_CASE(suppressionsLine0);

TEST_CASE(inlinesuppress);
TEST_CASE(inlinesuppress_symbolname);
Expand Down Expand Up @@ -401,6 +403,12 @@ class TestSuppressions : public TestFixture {
ASSERT_EQUALS(true, s2.isSuppressed(errorMessage("abc", "include/1.h", 142)));
}

void suppressionsLine0() {
Suppressions suppressions;
suppressions.addSuppressionLine("syntaxError:*:0");
ASSERT_EQUALS(true, suppressions.isSuppressed(errorMessage("syntaxError", "test.cpp", 0)));
}

void inlinesuppress() {
Suppressions::Suppression s;
std::string msg;
Expand Down