Fix #12181 (Suppressions: allow that id with * is added) (#5681)

This commit is contained in:
Daniel Marjamäki 2023-11-20 11:54:41 +01:00 committed by GitHub
parent 3bafe164a3
commit 036df0aca9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 12 deletions

View File

@ -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);
}
}
@ -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 + "\"";
}
}

View File

@ -451,10 +451,10 @@ The format for an error suppression is one of:
[error id]:[filename2]
[error id]
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.
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.
The filename may include the wildcard characters \* or ?, which matches any sequence of characters or any single character respectively.
It is recommended to use "/" as path separator on all operating systems. The filename must match the filename in the reported warning exactly.
The filename may include the wildcard characters \* or ?, which matches any sequence of characters or any single character respectively.
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.
For instance, if the warning contains a relative path, then the suppression must match that relative path.
## Command line suppression

View File

@ -51,6 +51,7 @@ private:
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);
@ -171,6 +172,14 @@ private:
}
}
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;