Skip to content

Commit 711ea51

Browse files
Fix #11450 cppcheck: error: Failed to add suppression. No id. (#6722)
1 parent 5b5e43e commit 711ea51

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

lib/suppressions.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,16 @@ std::string SuppressionList::parseFile(std::istream &istr)
8585
if (line.empty())
8686
continue;
8787

88+
std::string::size_type pos = 0;
89+
while (pos < line.size() && std::isspace(line[pos]))
90+
++pos;
91+
if (pos == line.size())
92+
continue;
93+
8894
// Skip comments
89-
if (line.length() > 1 && line[0] == '#')
95+
if (line[pos] == '#')
9096
continue;
91-
if (line.length() >= 2 && line[0] == '/' && line[1] == '/')
97+
if (pos < line.size() - 1 && line[pos] == '/' && line[pos + 1] == '/')
9298
continue;
9399

94100
const std::string errmsg(addSuppressionLine(line));

test/testsuppressions.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,12 @@ class TestSuppressions : public TestFixture {
967967
SuppressionList suppressions6;
968968
ASSERT_EQUALS("", suppressions6.parseFile(file6));
969969
ASSERT_EQUALS(true, suppressions6.isSuppressed(errorMessage("abc", "test.cpp", 123)));
970+
971+
std::istringstream file7(" // comment\n" // #11450
972+
"abc");
973+
SuppressionList suppressions7;
974+
ASSERT_EQUALS("", suppressions7.parseFile(file7));
975+
ASSERT_EQUALS(true, suppressions7.isSuppressed(errorMessage("abc", "test.cpp", 123)));
970976
}
971977

972978
void inlinesuppress() const {

0 commit comments

Comments
 (0)