Skip to content

Commit 83cb0b3

Browse files
shikamuPKEuS
authored andcommitted
--suppress on line 0 (danmar#1354)
Fixed --suppress on line 0
1 parent b16eb32 commit 83cb0b3

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

lib/errorlogger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ std::string ErrorLogger::ErrorMessage::FileLocation::stringify() const
611611
{
612612
std::ostringstream oss;
613613
oss << '[' << Path::toNativeSeparators(mFileName);
614-
if (line != 0)
614+
if (line != Suppressions::Suppression::NO_LINE)
615615
oss << ':' << line;
616616
oss << ']';
617617
return oss.str();

lib/suppressions.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ std::string Suppressions::addSuppressionLine(const std::string &line)
144144
std::istringstream istr1(suppression.fileName.substr(pos+1));
145145
istr1 >> suppression.lineNumber;
146146
} catch (...) {
147-
suppression.lineNumber = 0;
147+
suppression.lineNumber = Suppressions::Suppression::NO_LINE;
148148
}
149149

150-
if (suppression.lineNumber > 0) {
150+
if (suppression.lineNumber > Suppressions::Suppression::NO_LINE) {
151151
suppression.fileName.erase(pos);
152152
}
153153
}
@@ -233,7 +233,7 @@ bool Suppressions::Suppression::isSuppressed(const Suppressions::ErrorMessage &e
233233
return false;
234234
if (!fileName.empty() && !matchglob(fileName, errmsg.getFileName()))
235235
return false;
236-
if (lineNumber > 0 && lineNumber != errmsg.lineNumber)
236+
if (lineNumber > NO_LINE && lineNumber != errmsg.lineNumber)
237237
return false;
238238
if (!symbolName.empty()) {
239239
for (std::string::size_type pos = 0; pos < errmsg.symbolNames.size();) {
@@ -269,7 +269,7 @@ std::string Suppressions::Suppression::getText() const
269269
ret = errorId;
270270
if (!fileName.empty())
271271
ret += " fileName=" + fileName;
272-
if (lineNumber > 0)
272+
if (lineNumber > NO_LINE)
273273
ret += " lineNumber=" + MathLib::toString(lineNumber);
274274
if (!symbolName.empty())
275275
ret += " symbolName=" + symbolName;
@@ -312,7 +312,7 @@ void Suppressions::dump(std::ostream & out)
312312
out << " errorId=\"" << ErrorLogger::toxml(suppression.errorId) << '"';
313313
if (!suppression.fileName.empty())
314314
out << " fileName=\"" << ErrorLogger::toxml(suppression.fileName) << '"';
315-
if (suppression.lineNumber > 0)
315+
if (suppression.lineNumber > Suppression::NO_LINE)
316316
out << " lineNumber=\"" << suppression.lineNumber << '"';
317317
if (!suppression.symbolName.empty())
318318
out << " symbolName=\"" << ErrorLogger::toxml(suppression.symbolName) << '\"';

lib/suppressions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class CPPCHECKLIB Suppressions {
9898
std::string symbolName;
9999
bool matched;
100100

101-
static const int NO_LINE = 0;
101+
enum { NO_LINE = -1 };
102102
};
103103

104104
/**

test/testerrorlogger.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,15 @@ class TestErrorLogger : public TestFixture {
301301
errout.str("");
302302
suppressions.clear();
303303
suppressions.emplace_back("abc", "a.c", 10U);
304-
suppressions.emplace_back("unmatchedSuppression", "*", 0U);
304+
suppressions.emplace_back("unmatchedSuppression", "*", Suppressions::Suppression::NO_LINE);
305305
reportUnmatchedSuppressions(suppressions);
306306
ASSERT_EQUALS("", errout.str());
307307

308308
// suppress all unmatchedSuppression in a.c
309309
errout.str("");
310310
suppressions.clear();
311311
suppressions.emplace_back("abc", "a.c", 10U);
312-
suppressions.emplace_back("unmatchedSuppression", "a.c", 0U);
312+
suppressions.emplace_back("unmatchedSuppression", "a.c", Suppressions::Suppression::NO_LINE);
313313
reportUnmatchedSuppressions(suppressions);
314314
ASSERT_EQUALS("", errout.str());
315315

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

test/testsuppressions.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "suppressions.h"
2323
#include "testsuite.h"
2424
#include "threadexecutor.h"
25+
#include "path.h"
2526

2627
#include <cstddef>
2728
#include <list>
@@ -46,6 +47,7 @@ class TestSuppressions : public TestFixture {
4647
TEST_CASE(suppressionsSettings);
4748
TEST_CASE(suppressionsMultiFile);
4849
TEST_CASE(suppressionsPathSeparator);
50+
TEST_CASE(suppressionsLine0);
4951

5052
TEST_CASE(inlinesuppress);
5153
TEST_CASE(inlinesuppress_symbolname);
@@ -403,6 +405,12 @@ class TestSuppressions : public TestFixture {
403405
ASSERT_EQUALS(true, s2.isSuppressed(errorMessage("abc", "include/1.h", 142)));
404406
}
405407

408+
void suppressionsLine0() {
409+
Suppressions suppressions;
410+
suppressions.addSuppressionLine("syntaxError:*:0");
411+
ASSERT_EQUALS(true, suppressions.isSuppressed(errorMessage("syntaxError", "test.cpp", 0)));
412+
}
413+
406414
void inlinesuppress() {
407415
Suppressions::Suppression s;
408416
std::string msg;

0 commit comments

Comments
 (0)