From d300d1f61b2b368a1cba64b6f33b1d0e870d9725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 25 Jul 2018 07:43:50 +0200 Subject: [PATCH] Refactoring endsWith utility function --- lib/checkstring.cpp | 4 ++-- lib/utils.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/checkstring.cpp b/lib/checkstring.cpp index a4211d8b8..1ca3dc9c1 100644 --- a/lib/checkstring.cpp +++ b/lib/checkstring.cpp @@ -276,8 +276,8 @@ void CheckString::checkIncorrectStringCompare() for (const Scope * scope : symbolDatabase->functionScopes) { for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { // skip "assert(str && ..)" and "assert(.. && str)" - if ((endsWith(tok->str(), "assert", 6) || endsWith(tok->str(), "ASSERT", 6)) && - Token::Match(tok, "%name% (") && + if (Token::Match(tok, "%name% (") && + (endsWith(tok->str(), "assert") || endsWith(tok->str(), "ASSERT")) && (Token::Match(tok->tokAt(2), "%str% &&") || Token::Match(tok->next()->link()->tokAt(-2), "&& %str% )"))) tok = tok->next()->link(); diff --git a/lib/utils.h b/lib/utils.h index 9f22194e3..d281699e8 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -31,9 +31,9 @@ inline bool endsWith(const std::string &str, char c) return str[str.size()-1U] == c; } -inline bool endsWith(const std::string &str, const char end[], std::size_t endlen) +inline bool endsWith(const std::string &str, const std::string &end) { - return (str.size() >= endlen) && (str.compare(str.size()-endlen, endlen, end)==0); + return (str.size() >= end.size()) && (str.compare(str.size()-end.size(), end.size(), end)==0); } inline static const char *getOrdinalText(int i)