Fix inline suppressions problem

This commit is contained in:
Daniel Marjamäki 2020-09-10 21:46:15 +02:00
parent 6c53cdd6f9
commit 51f5f2c7d0
2 changed files with 8 additions and 6 deletions

View File

@ -83,15 +83,17 @@ namespace {
static bool parseInlineSuppressionCommentToken(const simplecpp::Token *tok, std::list<Suppressions::Suppression> &inlineSuppressions, std::list<BadInlineSuppression> *bad)
{
const std::string cppchecksuppress("cppcheck-suppress");
const std::string &comment = tok->str();
if (comment.size() < 19)
if (comment.size() < cppchecksuppress.size())
return false;
const std::string::size_type pos1 = comment.find_first_not_of("/* \t");
if (pos1 == std::string::npos)
return false;
if (pos1 + 17 >= comment.size())
if (pos1 + cppchecksuppress.size() >= comment.size())
return false;
if (comment.compare(pos1, 17, "cppcheck-suppress") != 0)
if (comment.substr(pos1, cppchecksuppress.size()) != cppchecksuppress)
return false;
// skip spaces after "cppcheck-suppress"

View File

@ -6,12 +6,12 @@ import re
from testutils import cppcheck
def test1():
ret, stdout, stderr = cppcheck(['--inline-suppr', 'proj-inline-suppress'])
ret, stdout, stderr = cppcheck(['-Iproj-inline-suppress', '--inline-suppr', 'proj-inline-suppress'])
assert ret == 0
# TODO assert len(stderr) == 0
assert stderr == ''
def test2():
ret, stdout, stderr = cppcheck(['proj-inline-suppress'])
ret, stdout, stderr = cppcheck(['-Iproj-inline-suppress', 'proj-inline-suppress'])
assert ret == 0
assert len(stderr) > 0