From 51f5f2c7d091c9e0e62b3e0fbfb7c20fddd3a0a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 10 Sep 2020 21:46:15 +0200 Subject: [PATCH] Fix inline suppressions problem --- lib/preprocessor.cpp | 8 +++++--- test/cli/test-inline-suppress.py | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index b4a68b47e..7d293f2ef 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -83,15 +83,17 @@ namespace { static bool parseInlineSuppressionCommentToken(const simplecpp::Token *tok, std::list &inlineSuppressions, std::list *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" diff --git a/test/cli/test-inline-suppress.py b/test/cli/test-inline-suppress.py index 579748997..eab4ace95 100644 --- a/test/cli/test-inline-suppress.py +++ b/test/cli/test-inline-suppress.py @@ -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