Skip to content

Commit 036df0a

Browse files
authored
Fix #12181 (Suppressions: allow that id with * is added) (#5681)
1 parent 3bafe16 commit 036df0a

3 files changed

Lines changed: 20 additions & 12 deletions

File tree

lib/suppressions.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ static bool isAcceptedErrorIdChar(char c)
5858
case '_':
5959
case '-':
6060
case '.':
61+
case '*':
6162
return true;
6263
default:
63-
return std::isalnum(c);
64+
return c > 0 && std::isalnum(c);
6465
}
6566
}
6667

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

258-
if (suppression.errorId != "*") {
259-
for (std::string::size_type pos = 0; pos < suppression.errorId.length(); ++pos) {
260-
if (suppression.errorId[pos] < 0 || !isAcceptedErrorIdChar(suppression.errorId[pos])) {
261-
return "Failed to add suppression. Invalid id \"" + suppression.errorId + "\"";
262-
}
263-
if (pos == 0 && std::isdigit(suppression.errorId[pos])) {
264-
return "Failed to add suppression. Invalid id \"" + suppression.errorId + "\"";
265-
}
259+
for (std::string::size_type pos = 0; pos < suppression.errorId.length(); ++pos) {
260+
if (!isAcceptedErrorIdChar(suppression.errorId[pos])) {
261+
return "Failed to add suppression. Invalid id \"" + suppression.errorId + "\"";
262+
}
263+
if (pos == 0 && std::isdigit(suppression.errorId[pos])) {
264+
return "Failed to add suppression. Invalid id \"" + suppression.errorId + "\"";
266265
}
267266
}
268267

man/manual.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,10 @@ The format for an error suppression is one of:
451451
[error id]:[filename2]
452452
[error id]
453453

454-
The `error id` is the id that you want to suppress. The easiest way to get it is to use the --template=gcc command line flag. The id is shown in brackets.
454+
The `error id` is the id that you want to suppress. The id of a warning is shown in brackets in the normal cppcheck text output. The suppression `error id` may contain \* to match any sequence of tokens.
455455

456-
The filename may include the wildcard characters \* or ?, which matches any sequence of characters or any single character respectively.
457-
It is recommended to use "/" as path separator on all operating systems. The filename must match the filename in the reported warning exactly.
456+
The filename may include the wildcard characters \* or ?, which matches any sequence of characters or any single character respectively.
457+
It is recommended to use forward-slash `/` as path separator on all operating systems. The filename must match the filename in the reported warning exactly.
458458
For instance, if the warning contains a relative path, then the suppression must match that relative path.
459459

460460
## Command line suppression

test/testsuppressions.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class TestSuppressions : public TestFixture {
5151
TEST_CASE(suppressionsDosFormat); // Ticket #1836
5252
TEST_CASE(suppressionsFileNameWithColon); // Ticket #1919 - filename includes colon
5353
TEST_CASE(suppressionsGlob);
54+
TEST_CASE(suppressionsGlobId);
5455
TEST_CASE(suppressionsFileNameWithExtraPath);
5556
TEST_CASE(suppressionsSettings);
5657
TEST_CASE(suppressionsSettingsThreads);
@@ -171,6 +172,14 @@ class TestSuppressions : public TestFixture {
171172
}
172173
}
173174

175+
void suppressionsGlobId() const {
176+
Suppressions suppressions;
177+
std::istringstream s("a*\n");
178+
ASSERT_EQUALS("", suppressions.parseFile(s));
179+
ASSERT_EQUALS(true, suppressions.isSuppressed(errorMessage("abc", "xyz.cpp", 1)));
180+
ASSERT_EQUALS(false, suppressions.isSuppressed(errorMessage("def", "xyz.cpp", 1)));
181+
}
182+
174183
void suppressionsFileNameWithExtraPath() const {
175184
// Ticket #2797
176185
Suppressions suppressions;

0 commit comments

Comments
 (0)