Skip to content

Commit

Permalink
Fix #12181 (Suppressions: allow that id with * is added)
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Nov 20, 2023
1 parent e01e090 commit 8e414d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ static bool isAcceptedErrorIdChar(char c)
case '_':
case '-':
case '.':
case '*':
return true;
default:
return std::isalnum(c);
return c > 0 && std::isalnum(c);
}
}

Expand Down Expand Up @@ -255,14 +256,12 @@ std::string Suppressions::addSuppression(Suppressions::Suppression suppression)
if (suppression.errorId.empty() && suppression.hash == 0)
return "Failed to add suppression. No id.";

if (suppression.errorId != "*") {
for (std::string::size_type pos = 0; pos < suppression.errorId.length(); ++pos) {
if (suppression.errorId[pos] < 0 || !isAcceptedErrorIdChar(suppression.errorId[pos])) {
return "Failed to add suppression. Invalid id \"" + suppression.errorId + "\"";
}
if (pos == 0 && std::isdigit(suppression.errorId[pos])) {
return "Failed to add suppression. Invalid id \"" + suppression.errorId + "\"";
}
for (std::string::size_type pos = 0; pos < suppression.errorId.length(); ++pos) {
if (!isAcceptedErrorIdChar(suppression.errorId[pos])) {
return "Failed to add suppression. Invalid id \"" + suppression.errorId + "\"";
}
if (pos == 0 && std::isdigit(suppression.errorId[pos])) {
return "Failed to add suppression. Invalid id \"" + suppression.errorId + "\"";
}
}

Expand Down
9 changes: 9 additions & 0 deletions test/testsuppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class TestSuppressions : public TestFixture {
TEST_CASE(suppressionsDosFormat); // Ticket #1836
TEST_CASE(suppressionsFileNameWithColon); // Ticket #1919 - filename includes colon
TEST_CASE(suppressionsGlob);
TEST_CASE(suppressionsGlobId);
TEST_CASE(suppressionsFileNameWithExtraPath);
TEST_CASE(suppressionsSettings);
TEST_CASE(suppressionsSettingsThreads);
Expand Down Expand Up @@ -171,6 +172,14 @@ class TestSuppressions : public TestFixture {
}
}

void suppressionsGlobId() const {
Suppressions suppressions;
std::istringstream s("a*\n");
ASSERT_EQUALS("", suppressions.parseFile(s));
ASSERT_EQUALS(true, suppressions.isSuppressed(errorMessage("abc", "xyz.cpp", 1)));
ASSERT_EQUALS(false, suppressions.isSuppressed(errorMessage("def", "xyz.cpp", 1)));
}

void suppressionsFileNameWithExtraPath() const {
// Ticket #2797
Suppressions suppressions;
Expand Down

0 comments on commit 8e414d8

Please sign in to comment.