Skip to content

Commit 93341f4

Browse files
committed
Use simple match where possible
Fixes these warnings found by "--enable=internal": [lib/checkclass.cpp:972]: (warning) Found simple pattern inside Token::Match() call: "* *" [lib/checkbufferoverrun.cpp:635]: (warning) Found simple pattern inside Token::Match() call: "." [lib/checkbufferoverrun.cpp:1397]: (warning) Found simple pattern inside Token::Match() call: ";" [lib/checksizeof.cpp:299]: (warning) Found simple pattern inside Token::Match() call: "." [lib/checksizeof.cpp:301]: (warning) Found simple pattern inside Token::Match() call: ")" [lib/checksizeof.cpp:303]: (warning) Found simple pattern inside Token::Match() call: "]" [lib/checksizeof.cpp:318]: (warning) Found simple pattern inside Token::Match() call: ")" [lib/checknullpointer.cpp:413]: (warning) Found simple pattern inside Token::Match() call: "delete" [lib/checkio.cpp:1336]: (warning) Found simple pattern inside Token::Match() call: "> (" [lib/checkstl.cpp:1509]: (warning) Found simple pattern inside Token::findmatch() call: ";" [lib/checkstl.cpp:1512]: (warning) Found simple pattern inside Token::findmatch() call: ";" [lib/checkstl.cpp:1594]: (warning) Found simple pattern inside Token::Match() call: "=" [lib/checkstl.cpp:1598]: (warning) Found simple pattern inside Token::Match() call: "] =" [lib/checkunusedvar.cpp:755]: (warning) Found simple pattern inside Token::Match() call: "goto" [lib/checkunusedvar.cpp:793]: (warning) Found simple pattern inside Token::Match() call: "=" [lib/checkuninitvar.cpp:376]: (warning) Found simple pattern inside Token::Match() call: "> (" [lib/checkother.cpp:86]: (warning) Found simple pattern inside Token::Match() call: "> (" [lib/checkother.cpp:2181]: (warning) Found simple pattern inside Token::Match() call: "> {" [lib/valueflow.cpp:54]: (warning) Found simple pattern inside Token::Match() call: "&" [lib/valueflow.cpp:409]: (warning) Found simple pattern inside Token::Match() call: "do" [lib/valueflow.cpp:425]: (warning) Found simple pattern inside Token::Match() call: ") {" [lib/valueflow.cpp:487]: (warning) Found simple pattern inside Token::Match() call: ") {" [lib/valueflow.cpp:511]: (warning) Found simple pattern inside Token::Match() call: "} else {" [lib/valueflow.cpp:615]: (warning) Found simple pattern inside Token::Match() call: "for (" [lib/symboldatabase.cpp:80]: (warning) Found simple pattern inside Token::Match() call: "= {" [lib/symboldatabase.cpp:1069]: (warning) Found simple pattern inside Token::Match() call: "std ::" [lib/tokenize.cpp:2207]: (warning) Found simple pattern inside Token::Match() call: "< >" [lib/tokenize.cpp:2730]: (warning) Found simple pattern inside Token::Match() call: ";" [lib/tokenize.cpp:4234]: (warning) Found simple pattern inside Token::Match() call: "try {" [lib/tokenize.cpp:4235]: (warning) Found simple pattern inside Token::Match() call: "} catch (" [lib/tokenize.cpp:5500]: (warning) Found simple pattern inside Token::Match() call: "INT8" [lib/tokenize.cpp:5752]: (warning) Found simple pattern inside Token::Match() call: "}" [lib/tokenize.cpp:5752]: (warning) Found simple pattern inside Token::Match() call: "do"
1 parent c625606 commit 93341f4

12 files changed

Lines changed: 32 additions & 32 deletions

lib/checkbufferoverrun.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int p
632632
}
633633
}
634634

635-
if (Token::Match(tok.previous(), ".") || Token::Match(tok.tokAt(-2), "!!std ::"))
635+
if (Token::simpleMatch(tok.previous(), ".") || Token::Match(tok.tokAt(-2), "!!std ::"))
636636
total_size.clear();
637637

638638
std::map<std::string, unsigned int>::const_iterator it = total_size.find(tok.str());
@@ -1394,7 +1394,7 @@ bool CheckBufferOverrun::isArrayOfStruct(const Token* tok, int &position)
13941394
} else
13951395
break;
13961396
}
1397-
if (Token::Match(tok->next(),";")) {
1397+
if (Token::simpleMatch(tok->next(),";")) {
13981398
position = i;
13991399
return true;
14001400
}

lib/checkclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ void CheckClass::checkMemset()
969969
if (var && arg1->strAt(1) == ",") {
970970
if (var->isPointer()) {
971971
derefs--;
972-
if (var->typeEndToken() && Token::Match(var->typeEndToken()->previous(), "* *")) // Check if it's a pointer to pointer
972+
if (var->typeEndToken() && Token::simpleMatch(var->typeEndToken()->previous(), "* *")) // Check if it's a pointer to pointer
973973
derefs--;
974974
}
975975

lib/checkio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings)
13331333
} else if (tok->str() == "&" || tok->type() == Token::eVariable ||
13341334
tok->type() == Token::eFunction || Token::Match(tok, "%type% ::") ||
13351335
(Token::Match(tok, "static_cast|reinterpret_cast|const_cast <") &&
1336-
Token::Match(tok->linkAt(1), "> (") &&
1336+
Token::simpleMatch(tok->linkAt(1), "> (") &&
13371337
Token::Match(tok->linkAt(1)->linkAt(1), ") ,|)"))) {
13381338
if (Token::Match(tok, "static_cast|reinterpret_cast|const_cast")) {
13391339
typeToken = tok->tokAt(2);

lib/checknullpointer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown)
410410
return false;
411411

412412
// OK to delete a null
413-
if (Token::Match(prev, "delete") || Token::Match(prev->tokAt(-2), "delete [ ]"))
413+
if (Token::simpleMatch(prev, "delete") || Token::Match(prev->tokAt(-2), "delete [ ]"))
414414
return false;
415415

416416
// OK to check if pointer is null

lib/checkother.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static bool isSameExpression(const Token *tok1, const Token *tok2, const std::se
8383
(Token::Match(tok2, "%var% <") && tok2->next()->link())) {
8484

8585
// non-const template function that is not a dynamic_cast => return false
86-
if (Token::Match(tok1->next()->link(), "> (") &&
86+
if (Token::simpleMatch(tok1->next()->link(), "> (") &&
8787
!(tok1->function() && tok1->function()->isConst) &&
8888
tok1->str() != "dynamic_cast")
8989
return false;
@@ -2178,7 +2178,7 @@ void CheckOther::checkIncompleteStatement()
21782178
tok = tok->linkAt(2);
21792179

21802180
// C++11 initialize set in initalizer list : [,:] std::set<int>{1} [{,]
2181-
else if (Token::Match(tok,"> {") && tok->link())
2181+
else if (Token::simpleMatch(tok,"> {") && tok->link())
21822182
tok = tok->next()->link();
21832183

21842184
else if (Token::Match(tok, "[;{}] %str%") || Token::Match(tok, "[;{}] %num%")) {

lib/checksizeof.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,11 @@ void CheckSizeof::sizeofVoid()
296296
const Token* tok2 = tok->tokAt(index);
297297
if (index == 0) {
298298
bool isMember = false;
299-
while (Token::Match(tok2->previous(), ".")) {
299+
while (Token::simpleMatch(tok2->previous(), ".")) {
300300
isMember = true;
301-
if (Token::Match(tok2->tokAt(-2), ")"))
301+
if (Token::simpleMatch(tok2->tokAt(-2), ")"))
302302
tok2 = tok2->tokAt(-2)->link();
303-
else if (Token::Match(tok2->tokAt(-2), "]"))
303+
else if (Token::simpleMatch(tok2->tokAt(-2), "]"))
304304
tok2 = tok2->tokAt(-2)->link()->previous();
305305
else
306306
tok2 = tok2->tokAt(-2);
@@ -315,7 +315,7 @@ void CheckSizeof::sizeofVoid()
315315
// Check for cast on operations with '+|-'
316316
if (Token::Match(tok, "%var% +|-")) {
317317
// Check for cast expression
318-
if (Token::Match(tok2->previous(), ")") && !Token::Match(tok2->previous()->link(), "( const| void *"))
318+
if (Token::simpleMatch(tok2->previous(), ")") && !Token::Match(tok2->previous()->link(), "( const| void *"))
319319
continue;
320320
}
321321
arithOperationsOnVoidPointerError(tok, varname,

lib/checkstl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,10 +1506,10 @@ void CheckStl::checkDereferenceInvalidIterator()
15061506

15071507
// For "for" loops, only search between the two semicolons
15081508
if (i->type == Scope::eFor) {
1509-
startOfCondition = Token::findmatch(tok->tokAt(2), ";", endOfCondition);
1509+
startOfCondition = Token::findsimplematch(tok->tokAt(2), ";", endOfCondition);
15101510
if (!startOfCondition)
15111511
continue;
1512-
endOfCondition = Token::findmatch(startOfCondition->next(), ";", endOfCondition);
1512+
endOfCondition = Token::findsimplematch(startOfCondition->next(), ";", endOfCondition);
15131513
if (!endOfCondition)
15141514
continue;
15151515
}
@@ -1591,11 +1591,11 @@ void CheckStl::readingEmptyStlContainer()
15911591
if (Token::Match(tok, "%var% =|[")) {
15921592
const Token *tok2;
15931593

1594-
if (Token::Match(tok->next(), "="))
1594+
if (Token::simpleMatch(tok->next(), "="))
15951595
tok2 = tok->tokAt(2);
15961596

15971597
// to check cases like Cmap[1]; or i = Cmap[1] -- the right wld evaluate true when token reaches it.
1598-
else if (Token::Match(tok->next()," [") && Token::Match(tok->linkAt(1),"] ="))
1598+
else if (Token::Match(tok->next()," [") && Token::simpleMatch(tok->linkAt(1),"] ="))
15991599
tok2 = tok->next()->link()->tokAt(2);
16001600

16011601
else

lib/checkuninitvar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ class UninitVar : public ExecutionPath {
373373
break;
374374
if (Token::Match(tok2, "%var% ("))
375375
break;
376-
if (Token::Match(tok2, "%var% <") && Token::Match(tok2->linkAt(1), "> ("))
376+
if (Token::Match(tok2, "%var% <") && Token::simpleMatch(tok2->linkAt(1), "> ("))
377377
break;
378378
if (tok2->varId() &&
379379
!Token::Match(tok2->previous(), "&|::") &&

lib/checkunusedvar.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
752752
variables.clear();
753753
break;
754754
}
755-
if (Token::Match(tok, "goto")) { // https://sourceforge.net/apps/trac/cppcheck/ticket/4447
755+
if (Token::simpleMatch(tok, "goto")) { // https://sourceforge.net/apps/trac/cppcheck/ticket/4447
756756
variables.clear();
757757
break;
758758
}
@@ -790,7 +790,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
790790
for (const Token *body = end->linkAt(-1); body != end; body = body->next()) {
791791
if (body->varId() == 0U)
792792
continue;
793-
if (!Token::Match(body->next(),"="))
793+
if (!Token::simpleMatch(body->next(),"="))
794794
readvar.insert(body->varId());
795795
else if (readvar.find(body->varId()) != readvar.end())
796796
variables.erase(body->varId());

lib/symboldatabase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
7777
if (tok2 && tok2->next()) {
7878
if (tok2->next()->str() == ";")
7979
tok = tok2->next();
80-
else if (Token::Match(tok2->next(), "= {") &&
80+
else if (Token::simpleMatch(tok2->next(), "= {") &&
8181
tok2->linkAt(2)->next()->str() == ";")
8282
tok = tok2->linkAt(2)->next();
8383
else if (Token::Match(tok2->next(), "(|{") &&
@@ -1066,7 +1066,7 @@ void Variable::evaluate()
10661066
setFlag(fIsArray, arrayDimensions(_dimensions, _name->next()));
10671067
if (_start) {
10681068
setFlag(fIsClass, !_start->isStandardType() && !isPointer() && !isReference());
1069-
_stlType = Token::Match(_start, "std ::");
1069+
_stlType = Token::simpleMatch(_start, "std ::");
10701070
}
10711071
if (_access == Argument) {
10721072
tok = _name;

0 commit comments

Comments
 (0)