Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ static bool parseInlineSuppressionCommentToken(const simplecpp::Token *tok, std:

// determine prefix if specified
if (posEndComment >= (pos1 + cppchecksuppress.size() + 1)) {
if (comment.at(pos1 + cppchecksuppress.size()) != '-')
const std::string suppressCmdString = comment.substr(pos1, pos2-pos1-1);
if (comment.at(pos1 + cppchecksuppress.size()) != '-') {
bad.emplace_back(tok->location.file(), tok->location.line, 0, "unknown suppression type '" + suppressCmdString + "'"); // TODO: set column
return false;
}

const unsigned int argumentLength =
posEndComment - (pos1 + cppchecksuppress.size() + 1);
Expand All @@ -122,8 +125,10 @@ static bool parseInlineSuppressionCommentToken(const simplecpp::Token *tok, std:
errorType = SuppressionList::Type::blockEnd;
else if ("macro" == suppressTypeString)
errorType = SuppressionList::Type::macro;
else
else {
bad.emplace_back(tok->location.file(), tok->location.line, 0, "unknown suppression type '" + suppressCmdString + "'"); // TODO: set column
return false;
}
}

if (comment[pos2] == '[') {
Expand Down
13 changes: 13 additions & 0 deletions test/testsuppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,19 @@ class TestSuppressions : public TestFixture {
"[test.cpp:3:5]: (error) Uninitialized variable: a [uninitvar]\n"
"[test.cpp:5:5]: (error) Uninitialized variable: b [uninitvar]\n", errout_str());

ASSERT_EQUALS(1, (this->*check)("// cppcheck-suppress: id\n"
"// cppcheck-suppress-unknown id\n"
"// cppcheck-suppress-begin-unknown id\n"
"// cppcheck-suppress-begin id4\n"
"void f() {}\n"
"// cppcheck-suppress-end-unknown id4\n",
""));
ASSERT_EQUALS("[test.cpp:1:0]: (error) unknown suppression type 'cppcheck-suppress:' [invalidSuppression]\n"
"[test.cpp:2:0]: (error) unknown suppression type 'cppcheck-suppress-unknown' [invalidSuppression]\n"
"[test.cpp:3:0]: (error) unknown suppression type 'cppcheck-suppress-begin-unknown' [invalidSuppression]\n"
"[test.cpp:6:0]: (error) unknown suppression type 'cppcheck-suppress-end-unknown' [invalidSuppression]\n"
"[test.cpp:4:0]: (error) Suppress Begin: No matching end [invalidSuppression]\n", errout_str());

ASSERT_EQUALS(1, (this->*check)("void f() {\n"
" int a;\n"
" // cppcheck-suppress-begin uninitvar\n"
Expand Down
Loading