Skip to content

Commit 7b22594

Browse files
authored
Replaced 'tok->next()->link()' by 'tok->linkAt(1)' (#6476)
Fixes from #6472
1 parent eeef6b8 commit 7b22594

22 files changed

+107
-107
lines changed

lib/astutils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ static bool isFunctionCall(const Token* tok)
484484
{
485485
if (Token::Match(tok, "%name% ("))
486486
return true;
487-
if (Token::Match(tok, "%name% <") && Token::simpleMatch(tok->next()->link(), "> ("))
487+
if (Token::Match(tok, "%name% <") && Token::simpleMatch(tok->linkAt(1), "> ("))
488488
return true;
489489
if (Token::Match(tok, "%name% ::"))
490490
return isFunctionCall(tok->tokAt(2));

lib/checkassert.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void CheckAssert::assertWithSideEffects()
5555
if (!Token::simpleMatch(tok, "assert ("))
5656
continue;
5757

58-
const Token *endTok = tok->next()->link();
58+
const Token *endTok = tok->linkAt(1);
5959
for (const Token* tmp = tok->next(); tmp != endTok; tmp = tmp->next()) {
6060
if (Token::simpleMatch(tmp, "sizeof ("))
6161
tmp = tmp->linkAt(1);

lib/checkboost.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void CheckBoost::checkBoostForeachModification()
4040
if (!Token::simpleMatch(tok, "BOOST_FOREACH ("))
4141
continue;
4242

43-
const Token *containerTok = tok->next()->link()->previous();
43+
const Token *containerTok = tok->linkAt(1)->previous();
4444
if (!Token::Match(containerTok, "%var% ) {"))
4545
continue;
4646

lib/checkbufferoverrun.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ void CheckBufferOverrun::stringNotZeroTerminated()
787787
}
788788
// Is the buffer zero terminated after the call?
789789
bool isZeroTerminated = false;
790-
for (const Token *tok2 = tok->next()->link(); tok2 != scope->bodyEnd; tok2 = tok2->next()) {
790+
for (const Token *tok2 = tok->linkAt(1); tok2 != scope->bodyEnd; tok2 = tok2->next()) {
791791
if (!Token::simpleMatch(tok2, "] ="))
792792
continue;
793793
const Token *rhs = tok2->next()->astOperand2();

lib/checkclass.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
949949
ftok = ftok->next();
950950

951951
// Passing "this" => assume that everything is initialized
952-
for (const Token *tok2 = ftok->next()->link(); tok2 && tok2 != ftok; tok2 = tok2->previous()) {
952+
for (const Token *tok2 = ftok->linkAt(1); tok2 && tok2 != ftok; tok2 = tok2->previous()) {
953953
if (tok2->str() == "this") {
954954
assignAllVar(usage);
955955
return;
@@ -1020,7 +1020,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
10201020
// the function is external and it's neither friend nor inherited virtual function.
10211021
// assume all variables that are passed to it are initialized..
10221022
else {
1023-
for (const Token *tok = ftok->tokAt(2); tok && tok != ftok->next()->link(); tok = tok->next()) {
1023+
for (const Token *tok = ftok->tokAt(2); tok && tok != ftok->linkAt(1); tok = tok->next()) {
10241024
if (tok->isName()) {
10251025
assignVar(usage, tok->varId());
10261026
}

lib/checkcondition.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1803,9 +1803,9 @@ void CheckCondition::checkDuplicateConditionalAssign()
18031803
for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
18041804
if (!Token::simpleMatch(tok, "if ("))
18051805
continue;
1806-
if (!Token::simpleMatch(tok->next()->link(), ") {"))
1806+
if (!Token::simpleMatch(tok->linkAt(1), ") {"))
18071807
continue;
1808-
const Token *blockTok = tok->next()->link()->next();
1808+
const Token *blockTok = tok->linkAt(1)->next();
18091809
const Token *condTok = tok->next()->astOperand2();
18101810
const bool isBoolVar = Token::Match(condTok, "!| %var%");
18111811
if (!isBoolVar && !Token::Match(condTok, "==|!="))

lib/checkexceptionsafety.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ void CheckExceptionSafety::destructors()
6363
for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
6464
// Skip try blocks
6565
if (Token::simpleMatch(tok, "try {")) {
66-
tok = tok->next()->link();
66+
tok = tok->linkAt(1);
6767
}
6868

6969
// Skip uncaught exceptions
7070
else if (Token::simpleMatch(tok, "if ( ! std :: uncaught_exception ( ) ) {")) {
71-
tok = tok->next()->link(); // end of if ( ... )
72-
tok = tok->next()->link(); // end of { ... }
71+
tok = tok->linkAt(1); // end of if ( ... )
72+
tok = tok->linkAt(1); // end of { ... }
7373
}
7474

7575
// throw found within a destructor
@@ -183,8 +183,8 @@ void CheckExceptionSafety::checkRethrowCopy()
183183
const unsigned int varid = scope.bodyStart->tokAt(-2)->varId();
184184
if (varid) {
185185
for (const Token* tok = scope.bodyStart->next(); tok && tok != scope.bodyEnd; tok = tok->next()) {
186-
if (Token::simpleMatch(tok, "catch (") && tok->next()->link() && tok->next()->link()->next()) { // Don't check inner catch - it is handled in another iteration of outer loop.
187-
tok = tok->next()->link()->next()->link();
186+
if (Token::simpleMatch(tok, "catch (") && tok->linkAt(1) && tok->linkAt(1)->next()) { // Don't check inner catch - it is handled in another iteration of outer loop.
187+
tok = tok->linkAt(1)->next()->link();
188188
if (!tok)
189189
break;
190190
} else if (Token::Match(tok, "%varid% .", varid)) {

lib/checkleakautovar.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
701701
continue;
702702
functionCall(ftok, openingPar, varInfo, allocation, af);
703703

704-
tok = ftok->next()->link();
704+
tok = ftok->linkAt(1);
705705

706706
// Handle scopes that might be noreturn
707707
if (allocation.status == VarInfo::NOALLOC && Token::simpleMatch(tok, ") ; }")) {

lib/checkmemoryleak.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ void CheckMemoryLeakNoVar::checkForUnsafeArgAlloc(const Scope *scope)
11031103

11041104
for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
11051105
if (Token::Match(tok, "%name% (")) {
1106-
const Token *endParamToken = tok->next()->link();
1106+
const Token *endParamToken = tok->linkAt(1);
11071107
const Token* pointerType = nullptr;
11081108
const Token* functionCalled = nullptr;
11091109

lib/checknullpointer.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
285285

286286
for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
287287
if (isUnevaluated(tok)) {
288-
tok = tok->next()->link();
288+
tok = tok->linkAt(1);
289289
continue;
290290
}
291291

@@ -347,15 +347,15 @@ void CheckNullPointer::nullConstantDereference()
347347

348348
for (; tok != scope->bodyEnd; tok = tok->next()) {
349349
if (isUnevaluated(tok))
350-
tok = tok->next()->link();
350+
tok = tok->linkAt(1);
351351

352352
else if (Token::simpleMatch(tok, "* 0")) {
353353
if (Token::Match(tok->previous(), "return|throw|;|{|}|:|[|(|,") || tok->previous()->isOp()) {
354354
nullPointerError(tok);
355355
}
356356
}
357357

358-
else if (Token::Match(tok, "0 [") && (tok->previous()->str() != "&" || !Token::Match(tok->next()->link()->next(), "[.(]")))
358+
else if (Token::Match(tok, "0 [") && (tok->previous()->str() != "&" || !Token::Match(tok->linkAt(1)->next(), "[.(]")))
359359
nullPointerError(tok);
360360

361361
else if (Token::Match(tok->previous(), "!!. %name% (|{") && (tok->previous()->str() != "::" || tok->strAt(-2) == "std")) {

lib/checkother.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3215,7 +3215,7 @@ void CheckOther::checkInterlockedDecrement()
32153215
raceAfterInterlockedDecrementError(checkStartTok);
32163216
}
32173217
} else if (Token::Match(tok, "if ( ::| InterlockedDecrement ( & %name%")) {
3218-
const Token* condEnd = tok->next()->link();
3218+
const Token* condEnd = tok->linkAt(1);
32193219
const Token* funcTok = tok->tokAt(2);
32203220
const Token* firstAccessTok = funcTok->str() == "::" ? funcTok->tokAt(4) : funcTok->tokAt(3);
32213221
if (condEnd && condEnd->next() && condEnd->next()->link()) {

lib/checkstl.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ void CheckStl::invalidContainer()
11101110
for (const Scope * scope : symbolDatabase->functionScopes) {
11111111
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
11121112
if (const Token* contTok = getLoopContainer(tok)) {
1113-
const Token* blockStart = tok->next()->link()->next();
1113+
const Token* blockStart = tok->linkAt(1)->next();
11141114
const Token* blockEnd = blockStart->link();
11151115
if (contTok->exprId() == 0)
11161116
continue;
@@ -1688,7 +1688,7 @@ void CheckStl::checkFindInsert()
16881688
for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
16891689
if (!Token::simpleMatch(tok, "if ("))
16901690
continue;
1691-
if (!Token::simpleMatch(tok->next()->link(), ") {"))
1691+
if (!Token::simpleMatch(tok->linkAt(1), ") {"))
16921692
continue;
16931693
if (!Token::Match(tok->next()->astOperand2(), "%comp%"))
16941694
continue;
@@ -1702,7 +1702,7 @@ void CheckStl::checkFindInsert()
17021702
if (mSettings->standards.cpp < Standards::CPP17 && !(keyTok && keyTok->valueType() && (keyTok->valueType()->isIntegral() || keyTok->valueType()->pointer > 0)))
17031703
continue;
17041704

1705-
const Token *thenTok = tok->next()->link()->next();
1705+
const Token *thenTok = tok->linkAt(1)->next();
17061706
const Token *valueTok = findInsertValue(thenTok, containerTok, keyTok, *mSettings);
17071707
if (!valueTok)
17081708
continue;
@@ -2040,7 +2040,7 @@ void CheckStl::string_c_str()
20402040
else
20412041
break;
20422042
if (!tok2 && j == i->second.n - 1)
2043-
tok2 = tok->next()->link();
2043+
tok2 = tok->linkAt(1);
20442044
else if (tok2)
20452045
tok2 = tok2->previous();
20462046
else
@@ -2420,7 +2420,7 @@ void CheckStl::checkDereferenceInvalidIterator2()
24202420

24212421
for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
24222422
if (Token::Match(tok, "sizeof|decltype|typeid|typeof (")) {
2423-
tok = tok->next()->link();
2423+
tok = tok->linkAt(1);
24242424
continue;
24252425
}
24262426

@@ -2742,7 +2742,7 @@ namespace {
27422742
std::set<nonneg int> varsChanged;
27432743

27442744
explicit LoopAnalyzer(const Token* tok, const Settings* psettings)
2745-
: bodyTok(tok->next()->link()->next()), settings(psettings)
2745+
: bodyTok(tok->linkAt(1)->next()), settings(psettings)
27462746
{
27472747
const Token* splitTok = tok->next()->astOperand2();
27482748
if (Token::simpleMatch(splitTok, ":") && splitTok->previous()->varId() != 0) {
@@ -2893,7 +2893,7 @@ void CheckStl::useStlAlgorithm()
28932893
// Parse range-based for loop
28942894
if (!Token::simpleMatch(tok, "for ("))
28952895
continue;
2896-
if (!Token::simpleMatch(tok->next()->link(), ") {"))
2896+
if (!Token::simpleMatch(tok->linkAt(1), ") {"))
28972897
continue;
28982898
LoopAnalyzer a{tok, mSettings};
28992899
std::string algoName = a.findAlgo();
@@ -2902,7 +2902,7 @@ void CheckStl::useStlAlgorithm()
29022902
continue;
29032903
}
29042904

2905-
const Token *bodyTok = tok->next()->link()->next();
2905+
const Token *bodyTok = tok->linkAt(1)->next();
29062906
const Token *splitTok = tok->next()->astOperand2();
29072907
const Token* loopVar{};
29082908
bool isIteratorLoop = false;
@@ -3114,7 +3114,7 @@ void CheckStl::knownEmptyContainer()
31143114

31153115
// Parse range-based for loop
31163116
if (tok->str() == "for") {
3117-
if (!Token::simpleMatch(tok->next()->link(), ") {"))
3117+
if (!Token::simpleMatch(tok->linkAt(1), ") {"))
31183118
continue;
31193119
const Token *splitTok = tok->next()->astOperand2();
31203120
if (!Token::simpleMatch(splitTok, ":"))

lib/checkstring.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ void CheckString::checkIncorrectStringCompare()
287287
// skip "assert(str && ..)" and "assert(.. && str)"
288288
if ((endsWith(tok->str(), "assert") || endsWith(tok->str(), "ASSERT")) &&
289289
Token::Match(tok, "%name% (") &&
290-
(Token::Match(tok->tokAt(2), "%str% &&") || Token::Match(tok->next()->link()->tokAt(-2), "&& %str% )")))
291-
tok = tok->next()->link();
290+
(Token::Match(tok->tokAt(2), "%str% &&") || Token::Match(tok->linkAt(1)->tokAt(-2), "&& %str% )")))
291+
tok = tok->linkAt(1);
292292

293293
if (Token::simpleMatch(tok, ". substr (") && Token::Match(tok->tokAt(3)->nextArgument(), "%num% )")) {
294294
const MathLib::biguint clen = MathLib::toBigUNumber(tok->linkAt(2)->strAt(-1));

lib/checkuninitvar.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
503503
}
504504

505505
// goto the {
506-
tok = tok->next()->link()->next();
506+
tok = tok->linkAt(1)->next();
507507

508508
if (!tok)
509509
break;
@@ -583,7 +583,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
583583
// = { .. }
584584
else if (Token::simpleMatch(tok, "= {") || (Token::Match(tok, "%name% {") && tok->variable() && tok == tok->variable()->nameToken())) {
585585
// end token
586-
const Token *end = tok->next()->link();
586+
const Token *end = tok->linkAt(1);
587587

588588
// If address of variable is taken in the block then bail out
589589
if (var.isPointer() || var.isArray()) {
@@ -630,7 +630,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
630630
return true;
631631

632632
// goto the {
633-
const Token *tok2 = forwhile ? tok->next()->link()->next() : tok->next();
633+
const Token *tok2 = forwhile ? tok->linkAt(1)->next() : tok->next();
634634

635635
if (tok2 && tok2->str() == "{") {
636636
const bool init = checkLoopBody(tok2, var, *alloc, membervar, (number_of_if > 0) || suppressErrors);
@@ -642,7 +642,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
642642
// is variable used in for-head?
643643
bool initcond = false;
644644
if (!suppressErrors) {
645-
const Token *startCond = forwhile ? tok->next() : tok->next()->link()->tokAt(2);
645+
const Token *startCond = forwhile ? tok->next() : tok->linkAt(1)->tokAt(2);
646646
initcond = checkIfForWhileHead(startCond, var, false, bool(number_of_if == 0), *alloc, membervar);
647647
}
648648

lib/checkunusedvar.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1069,8 +1069,8 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
10691069
} else if (Token::Match(tok, "[(,] & %var% [,)]")) {
10701070
variables.eraseAll(tok->tokAt(2)->varId());
10711071
} else if (Token::Match(tok, "[(,] (") &&
1072-
Token::Match(tok->next()->link(), ") %var% [,)[]")) {
1073-
variables.use(tok->next()->link()->next()->varId(), tok); // use = read + write
1072+
Token::Match(tok->linkAt(1), ") %var% [,)[]")) {
1073+
variables.use(tok->linkAt(1)->next()->varId(), tok); // use = read + write
10741074
} else if (Token::Match(tok, "[(,] *| *| %var%")) {
10751075
const Token* vartok = tok->next();
10761076
while (vartok->str() == "*")

lib/forwardanalyzer.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -656,13 +656,13 @@ namespace {
656656
return Break();
657657
}
658658
} else if (tok->isControlFlowKeyword() && Token::Match(tok, "if|while|for (") &&
659-
Token::simpleMatch(tok->next()->link(), ") {")) {
659+
Token::simpleMatch(tok->linkAt(1), ") {")) {
660660
if ((settings.vfOptions.maxForwardBranches > 0) && (++branchCount > settings.vfOptions.maxForwardBranches)) {
661661
// TODO: should be logged on function-level instead of file-level
662662
reportError(Severity::information, "normalCheckLevelMaxBranches", "Limiting analysis of branches. Use --check-level=exhaustive to analyze all branches.");
663663
return Break(Analyzer::Terminate::Bail);
664664
}
665-
Token* endCond = tok->next()->link();
665+
Token* endCond = tok->linkAt(1);
666666
Token* endBlock = endCond->next()->link();
667667
Token* condTok = getCondTok(tok);
668668
Token* initTok = getInitTok(tok);
@@ -769,7 +769,7 @@ namespace {
769769
}
770770
}
771771
} else if (Token::simpleMatch(tok, "try {")) {
772-
Token* endBlock = tok->next()->link();
772+
Token* endBlock = tok->linkAt(1);
773773
ForwardTraversal tryTraversal = fork();
774774
tryTraversal.updateScope(endBlock, depth - 1);
775775
bool bail = tryTraversal.actions.isModified();
@@ -792,7 +792,7 @@ namespace {
792792
return Break();
793793
tok = endBlock;
794794
} else if (Token::simpleMatch(tok, "do {")) {
795-
Token* endBlock = tok->next()->link();
795+
Token* endBlock = tok->linkAt(1);
796796
Token* condTok = Token::simpleMatch(endBlock, "} while (") ? endBlock->tokAt(2)->astOperand2() : nullptr;
797797
if (updateLoop(end, endBlock, condTok) == Progress::Break)
798798
return Break();

lib/pathanalysis.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ PathAnalysis::Progress PathAnalysis::forwardRange(const Token* startToken, const
123123
if (Token::simpleMatch(tok, "} else {")) {
124124
tok = tok->linkAt(2);
125125
}
126-
} else if (Token::Match(tok, "if|while|for (") && Token::simpleMatch(tok->next()->link(), ") {")) {
127-
const Token * endCond = tok->next()->link();
126+
} else if (Token::Match(tok, "if|while|for (") && Token::simpleMatch(tok->linkAt(1), ") {")) {
127+
const Token * endCond = tok->linkAt(1);
128128
const Token * endBlock = endCond->next()->link();
129129
const Token * condTok = getCondTok(tok);
130130
if (!condTok)
131131
continue;
132132
// Traverse condition
133-
if (forwardRange(tok->next(), tok->next()->link(), info, f) == Progress::Break)
133+
if (forwardRange(tok->next(), tok->linkAt(1), info, f) == Progress::Break)
134134
return Progress::Break;
135135
Info i = info;
136136
i.known = false;

0 commit comments

Comments
 (0)