Skip to content

Commit 06a2c35

Browse files
committed
removed SuppressionList::Suppression::NO_LINE [skip ci]
The suppressions were using `-1` as indication that no line is used but in simplecpp `0` was used for that.
1 parent 6bbfee2 commit 06a2c35

File tree

11 files changed

+45
-49
lines changed

11 files changed

+45
-49
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ $(libcppdir)/cppcheck.o: lib/cppcheck.cpp externals/picojson/picojson.h external
590590
$(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
591591
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/ctu.cpp
592592

593-
$(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
593+
$(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
594594
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/errorlogger.cpp
595595

596596
$(libcppdir)/errortypes.o: lib/errortypes.cpp lib/config.h lib/errortypes.h lib/utils.h
@@ -785,7 +785,7 @@ test/testconstructors.o: test/testconstructors.cpp lib/addoninfo.h lib/check.h l
785785
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
786786
$(CXX) ${INCLUDE_FOR_TEST} ${CFLAGS_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testcppcheck.cpp
787787

788-
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
788+
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
789789
$(CXX) ${INCLUDE_FOR_TEST} ${CFLAGS_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testerrorlogger.cpp
790790

791791
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

cli/cppcheckexecutor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ static std::vector<ErrorMessage> getUnmatchedSuppressions(const std::list<Suppre
311311
for (const SuppressionList::Suppression &s2 : unmatched) {
312312
if (s2.errorId == "unmatchedSuppression") { // TODO: handle unmatchedPolyspaceSuppression?
313313
if ((s2.fileName.empty() || s2.fileName == "*" || s2.fileName == s.fileName) &&
314-
(s2.lineNumber == SuppressionList::Suppression::NO_LINE || s2.lineNumber == s.lineNumber)) {
314+
(s2.lineNumber == 0 || s2.lineNumber == s.lineNumber)) {
315315
suppressed = true;
316316
break;
317317
}
@@ -329,7 +329,7 @@ static std::vector<ErrorMessage> getUnmatchedSuppressions(const std::list<Suppre
329329

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

gui/projectfiledialog.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,12 @@ static std::string suppressionAsText(const SuppressionList::Suppression& s)
9696
std::string ret;
9797
if (!s.errorId.empty())
9898
ret = s.errorId;
99-
if (!s.fileName.empty())
99+
if (!s.fileName.empty()) {
100100
ret += " fileName=" + s.fileName;
101-
if (s.lineNumber != SuppressionList::Suppression::NO_LINE)
102-
ret += " lineNumber=" + std::to_string(s.lineNumber);
101+
if (s.lineNumber != 0)
102+
ret += " lineNumber=" + std::to_string(s.lineNumber);
103+
// do not include column as suppressions are only line-based
104+
}
103105
if (!s.symbolName.empty())
104106
ret += " symbolName=" + s.symbolName;
105107
if (s.hash > 0)

lib/errorlogger.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "cppcheck.h"
2323
#include "path.h"
2424
#include "settings.h"
25-
#include "suppressions.h"
2625
#include "token.h"
2726
#include "tokenlist.h"
2827
#include "utils.h"
@@ -766,13 +765,11 @@ std::string ErrorMessage::FileLocation::stringify(bool addcolumn) const
766765
std::string str;
767766
str += '[';
768767
str += Path::toNativeSeparators(mFileName);
769-
if (line != SuppressionList::Suppression::NO_LINE) { // TODO: should not depend on Suppression
768+
str += ':';
769+
str += std::to_string(line);
770+
if (addcolumn) {
770771
str += ':';
771-
str += std::to_string(line);
772-
if (addcolumn) {
773-
str += ':';
774-
str += std::to_string(column);
775-
}
772+
str += std::to_string(column);
776773
}
777774
str += ']';
778775
return str;

lib/errorlogger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class CPPCHECKLIB ErrorMessage {
8888
std::string stringify(bool addcolumn = false) const;
8989

9090
unsigned int fileIndex;
91-
int line; // negative value means "no line"
91+
int line; // TODO: should be unsigned
9292
unsigned int column;
9393

9494
const std::string& getinfo() const {

lib/importproject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings &setti
14341434
s.fileName = empty_if_null(child->Attribute("fileName"));
14351435
if (!s.fileName.empty())
14361436
s.fileName = joinRelativePath(path, s.fileName);
1437-
s.lineNumber = child->IntAttribute("lineNumber", SuppressionList::Suppression::NO_LINE); // TODO: should not depend on Suppression
1437+
s.lineNumber = child->IntAttribute("lineNumber", 0);
14381438
s.symbolName = empty_if_null(child->Attribute("symbolName"));
14391439
s.hash = strToInt<std::size_t>(default_if_null(child->Attribute("hash"), "0"));
14401440
suppressions.push_back(std::move(s));

lib/suppressions.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ SuppressionList::ErrorMessage SuppressionList::ErrorMessage::fromErrorMessage(co
5050
ret.lineNumber = msg.callStack.back().line;
5151
} else {
5252
ret.setFileName(msg.file0);
53-
ret.lineNumber = SuppressionList::Suppression::NO_LINE;
53+
ret.lineNumber = 0;
5454
}
5555
ret.certainty = msg.certainty;
5656
ret.symbolNames = msg.symbolNames();
@@ -415,7 +415,7 @@ SuppressionList::Suppression::Result SuppressionList::Suppression::isSuppressed(
415415
if (!errorId.empty() && !matchglob(errorId, errmsg.errorId))
416416
return Result::Checked;
417417
} else {
418-
if ((SuppressionList::Type::unique == type) && (lineNumber != NO_LINE) && (lineNumber != errmsg.lineNumber)) {
418+
if ((SuppressionList::Type::unique == type) && (lineNumber != 0) && (lineNumber != errmsg.lineNumber)) {
419419
if (!thisAndNextLine || lineNumber + 1 != errmsg.lineNumber)
420420
return Result::None;
421421
}
@@ -524,15 +524,15 @@ void SuppressionList::dump(std::ostream & out, const std::string& filePath) cons
524524
out << " errorId=\"" << ErrorLogger::toxml(suppression.errorId) << '"';
525525
if (!suppression.fileName.empty())
526526
out << " fileName=\"" << ErrorLogger::toxml(suppression.fileName) << '"';
527-
if (suppression.lineNumber != Suppression::NO_LINE)
527+
if (suppression.lineNumber != 0)
528528
out << " lineNumber=\"" << suppression.lineNumber << '"';
529529
if (!suppression.symbolName.empty())
530530
out << " symbolName=\"" << ErrorLogger::toxml(suppression.symbolName) << '\"';
531531
if (suppression.hash > 0)
532532
out << " hash=\"" << suppression.hash << '\"';
533-
if (suppression.lineBegin != Suppression::NO_LINE)
533+
if (suppression.lineBegin != 0)
534534
out << " lineBegin=\"" << suppression.lineBegin << '"';
535-
if (suppression.lineEnd != Suppression::NO_LINE)
535+
if (suppression.lineEnd != 0)
536536
out << " lineEnd=\"" << suppression.lineEnd << '"';
537537
if (suppression.type == SuppressionList::Type::file)
538538
out << " type=\"file\"";
@@ -565,7 +565,7 @@ std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedLocalSuppre
565565
continue;
566566
if (s.matched)
567567
continue;
568-
if ((s.lineNumber != Suppression::NO_LINE) && !s.checked)
568+
if ((s.lineNumber != 0) && !s.checked)
569569
continue;
570570
if (s.type == SuppressionList::Type::macro)
571571
continue;
@@ -661,7 +661,7 @@ std::string SuppressionList::Suppression::toString() const
661661
if (!fileName.empty()) {
662662
s += ':';
663663
s += fileName;
664-
if (lineNumber != -1) {
664+
if (lineNumber != 0) {
665665
s += ':';
666666
s += std::to_string(lineNumber);
667667
}

lib/suppressions.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class CPPCHECKLIB SuppressionList {
6969

7070
struct CPPCHECKLIB Suppression {
7171
Suppression() = default;
72-
Suppression(std::string id, std::string file, int line=NO_LINE) : errorId(std::move(id)), fileName(std::move(file)), lineNumber(line) {}
72+
Suppression(std::string id, std::string file, int line=0) : errorId(std::move(id)), fileName(std::move(file)), lineNumber(line) {}
7373

7474
bool operator<(const Suppression &other) const {
7575
if (errorId != other.errorId)
@@ -153,9 +153,9 @@ class CPPCHECKLIB SuppressionList {
153153
std::string extraComment;
154154
// TODO: use simplecpp::Location?
155155
int fileIndex{};
156-
int lineNumber = NO_LINE; // TODO: needs to be unsigned
157-
int lineBegin = NO_LINE;
158-
int lineEnd = NO_LINE;
156+
unsigned int lineNumber{};
157+
int lineBegin{};
158+
int lineEnd {};
159159
int column{};
160160
Type type = Type::unique;
161161
std::string symbolName;
@@ -166,8 +166,6 @@ class CPPCHECKLIB SuppressionList {
166166
bool checked{}; /** This suppression applied to code which was being analyzed but did not match the error in an isSuppressed() call */
167167
bool isInline{};
168168
bool isPolyspace{};
169-
170-
enum : std::int8_t { NO_LINE = -1 };
171169
};
172170

173171
/**

oss-fuzz/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ $(libcppdir)/cppcheck.o: ../lib/cppcheck.cpp ../externals/picojson/picojson.h ..
266266
$(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
267267
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/ctu.cpp
268268

269-
$(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
269+
$(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
270270
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/errorlogger.cpp
271271

272272
$(libcppdir)/errortypes.o: ../lib/errortypes.cpp ../lib/config.h ../lib/errortypes.h ../lib/utils.h

test/testerrorlogger.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "errortypes.h"
2323
#include "fixture.h"
2424
#include "helpers.h"
25-
#include "suppressions.h"
2625

2726
#include <list>
2827
#include <string>
@@ -237,14 +236,14 @@ class TestErrorLogger : public TestFixture {
237236
}
238237

239238
void FileLocationSetFile2() const {
240-
ErrorMessage::FileLocation loc("foo1.cpp", SuppressionList::Suppression::NO_LINE, 0); // TODO: should not depend on Suppression
239+
ErrorMessage::FileLocation loc("foo1.cpp", 0, 0);
241240
loc.setfile("foo.cpp");
242241
ASSERT_EQUALS("foo1.cpp", loc.getOrigFile(false));
243242
ASSERT_EQUALS("foo.cpp", loc.getfile(false));
244-
ASSERT_EQUALS(SuppressionList::Suppression::NO_LINE, loc.line);
243+
ASSERT_EQUALS(0, loc.line);
245244
ASSERT_EQUALS(0, loc.column);
246-
ASSERT_EQUALS("[foo.cpp]", loc.stringify(false));
247-
ASSERT_EQUALS("[foo.cpp]", loc.stringify(true));
245+
ASSERT_EQUALS("[foo.cpp:0]", loc.stringify(false));
246+
ASSERT_EQUALS("[foo.cpp:0:0]", loc.stringify(true));
248247
}
249248

250249
void ErrorMessageConstruct() const {

0 commit comments

Comments
 (0)