Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ static bool isFunctionCall(const Token* tok)
{
if (Token::Match(tok, "%name% ("))
return true;
if (Token::Match(tok, "%name% <") && Token::simpleMatch(tok->next()->link(), "> ("))
if (Token::Match(tok, "%name% <") && Token::simpleMatch(tok->linkAt(1), "> ("))
return true;
if (Token::Match(tok, "%name% ::"))
return isFunctionCall(tok->tokAt(2));
Expand Down
2 changes: 1 addition & 1 deletion lib/checkassert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void CheckAssert::assertWithSideEffects()
if (!Token::simpleMatch(tok, "assert ("))
continue;

const Token *endTok = tok->next()->link();
const Token *endTok = tok->linkAt(1);
for (const Token* tmp = tok->next(); tmp != endTok; tmp = tmp->next()) {
if (Token::simpleMatch(tmp, "sizeof ("))
tmp = tmp->linkAt(1);
Expand Down
2 changes: 1 addition & 1 deletion lib/checkboost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void CheckBoost::checkBoostForeachModification()
if (!Token::simpleMatch(tok, "BOOST_FOREACH ("))
continue;

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

Expand Down
2 changes: 1 addition & 1 deletion lib/checkbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ void CheckBufferOverrun::stringNotZeroTerminated()
}
// Is the buffer zero terminated after the call?
bool isZeroTerminated = false;
for (const Token *tok2 = tok->next()->link(); tok2 != scope->bodyEnd; tok2 = tok2->next()) {
for (const Token *tok2 = tok->linkAt(1); tok2 != scope->bodyEnd; tok2 = tok2->next()) {
if (!Token::simpleMatch(tok2, "] ="))
continue;
const Token *rhs = tok2->next()->astOperand2();
Expand Down
4 changes: 2 additions & 2 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
ftok = ftok->next();

// Passing "this" => assume that everything is initialized
for (const Token *tok2 = ftok->next()->link(); tok2 && tok2 != ftok; tok2 = tok2->previous()) {
for (const Token *tok2 = ftok->linkAt(1); tok2 && tok2 != ftok; tok2 = tok2->previous()) {
if (tok2->str() == "this") {
assignAllVar(usage);
return;
Expand Down Expand Up @@ -1020,7 +1020,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
// the function is external and it's neither friend nor inherited virtual function.
// assume all variables that are passed to it are initialized..
else {
for (const Token *tok = ftok->tokAt(2); tok && tok != ftok->next()->link(); tok = tok->next()) {
for (const Token *tok = ftok->tokAt(2); tok && tok != ftok->linkAt(1); tok = tok->next()) {
if (tok->isName()) {
assignVar(usage, tok->varId());
}
Expand Down
4 changes: 2 additions & 2 deletions lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1803,9 +1803,9 @@ void CheckCondition::checkDuplicateConditionalAssign()
for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
if (!Token::simpleMatch(tok, "if ("))
continue;
if (!Token::simpleMatch(tok->next()->link(), ") {"))
if (!Token::simpleMatch(tok->linkAt(1), ") {"))
continue;
const Token *blockTok = tok->next()->link()->next();
const Token *blockTok = tok->linkAt(1)->next();
const Token *condTok = tok->next()->astOperand2();
const bool isBoolVar = Token::Match(condTok, "!| %var%");
if (!isBoolVar && !Token::Match(condTok, "==|!="))
Expand Down
10 changes: 5 additions & 5 deletions lib/checkexceptionsafety.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ void CheckExceptionSafety::destructors()
for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
// Skip try blocks
if (Token::simpleMatch(tok, "try {")) {
tok = tok->next()->link();
tok = tok->linkAt(1);
}

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

// throw found within a destructor
Expand Down Expand Up @@ -183,8 +183,8 @@ void CheckExceptionSafety::checkRethrowCopy()
const unsigned int varid = scope.bodyStart->tokAt(-2)->varId();
if (varid) {
for (const Token* tok = scope.bodyStart->next(); tok && tok != scope.bodyEnd; tok = tok->next()) {
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.
tok = tok->next()->link()->next()->link();
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.
tok = tok->linkAt(1)->next()->link();
if (!tok)
break;
} else if (Token::Match(tok, "%varid% .", varid)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
continue;
functionCall(ftok, openingPar, varInfo, allocation, af);

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

// Handle scopes that might be noreturn
if (allocation.status == VarInfo::NOALLOC && Token::simpleMatch(tok, ") ; }")) {
Expand Down
2 changes: 1 addition & 1 deletion lib/checkmemoryleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ void CheckMemoryLeakNoVar::checkForUnsafeArgAlloc(const Scope *scope)

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

Expand Down
6 changes: 3 additions & 3 deletions lib/checknullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ void CheckNullPointer::nullPointerByDeRefAndChec()

for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
if (isUnevaluated(tok)) {
tok = tok->next()->link();
tok = tok->linkAt(1);
continue;
}

Expand Down Expand Up @@ -347,15 +347,15 @@ void CheckNullPointer::nullConstantDereference()

for (; tok != scope->bodyEnd; tok = tok->next()) {
if (isUnevaluated(tok))
tok = tok->next()->link();
tok = tok->linkAt(1);

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

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

else if (Token::Match(tok->previous(), "!!. %name% (|{") && (tok->previous()->str() != "::" || tok->strAt(-2) == "std")) {
Expand Down
2 changes: 1 addition & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3215,7 +3215,7 @@ void CheckOther::checkInterlockedDecrement()
raceAfterInterlockedDecrementError(checkStartTok);
}
} else if (Token::Match(tok, "if ( ::| InterlockedDecrement ( & %name%")) {
const Token* condEnd = tok->next()->link();
const Token* condEnd = tok->linkAt(1);
const Token* funcTok = tok->tokAt(2);
const Token* firstAccessTok = funcTok->str() == "::" ? funcTok->tokAt(4) : funcTok->tokAt(3);
if (condEnd && condEnd->next() && condEnd->next()->link()) {
Expand Down
18 changes: 9 additions & 9 deletions lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ void CheckStl::invalidContainer()
for (const Scope * scope : symbolDatabase->functionScopes) {
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
if (const Token* contTok = getLoopContainer(tok)) {
const Token* blockStart = tok->next()->link()->next();
const Token* blockStart = tok->linkAt(1)->next();
const Token* blockEnd = blockStart->link();
if (contTok->exprId() == 0)
continue;
Expand Down Expand Up @@ -1688,7 +1688,7 @@ void CheckStl::checkFindInsert()
for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
if (!Token::simpleMatch(tok, "if ("))
continue;
if (!Token::simpleMatch(tok->next()->link(), ") {"))
if (!Token::simpleMatch(tok->linkAt(1), ") {"))
continue;
if (!Token::Match(tok->next()->astOperand2(), "%comp%"))
continue;
Expand All @@ -1702,7 +1702,7 @@ void CheckStl::checkFindInsert()
if (mSettings->standards.cpp < Standards::CPP17 && !(keyTok && keyTok->valueType() && (keyTok->valueType()->isIntegral() || keyTok->valueType()->pointer > 0)))
continue;

const Token *thenTok = tok->next()->link()->next();
const Token *thenTok = tok->linkAt(1)->next();
const Token *valueTok = findInsertValue(thenTok, containerTok, keyTok, *mSettings);
if (!valueTok)
continue;
Expand Down Expand Up @@ -2040,7 +2040,7 @@ void CheckStl::string_c_str()
else
break;
if (!tok2 && j == i->second.n - 1)
tok2 = tok->next()->link();
tok2 = tok->linkAt(1);
else if (tok2)
tok2 = tok2->previous();
else
Expand Down Expand Up @@ -2420,7 +2420,7 @@ void CheckStl::checkDereferenceInvalidIterator2()

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

Expand Down Expand Up @@ -2742,7 +2742,7 @@ namespace {
std::set<nonneg int> varsChanged;

explicit LoopAnalyzer(const Token* tok, const Settings* psettings)
: bodyTok(tok->next()->link()->next()), settings(psettings)
: bodyTok(tok->linkAt(1)->next()), settings(psettings)
{
const Token* splitTok = tok->next()->astOperand2();
if (Token::simpleMatch(splitTok, ":") && splitTok->previous()->varId() != 0) {
Expand Down Expand Up @@ -2893,7 +2893,7 @@ void CheckStl::useStlAlgorithm()
// Parse range-based for loop
if (!Token::simpleMatch(tok, "for ("))
continue;
if (!Token::simpleMatch(tok->next()->link(), ") {"))
if (!Token::simpleMatch(tok->linkAt(1), ") {"))
continue;
LoopAnalyzer a{tok, mSettings};
std::string algoName = a.findAlgo();
Expand All @@ -2902,7 +2902,7 @@ void CheckStl::useStlAlgorithm()
continue;
}

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

// Parse range-based for loop
if (tok->str() == "for") {
if (!Token::simpleMatch(tok->next()->link(), ") {"))
if (!Token::simpleMatch(tok->linkAt(1), ") {"))
continue;
const Token *splitTok = tok->next()->astOperand2();
if (!Token::simpleMatch(splitTok, ":"))
Expand Down
4 changes: 2 additions & 2 deletions lib/checkstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ void CheckString::checkIncorrectStringCompare()
// skip "assert(str && ..)" and "assert(.. && str)"
if ((endsWith(tok->str(), "assert") || endsWith(tok->str(), "ASSERT")) &&
Token::Match(tok, "%name% (") &&
(Token::Match(tok->tokAt(2), "%str% &&") || Token::Match(tok->next()->link()->tokAt(-2), "&& %str% )")))
tok = tok->next()->link();
(Token::Match(tok->tokAt(2), "%str% &&") || Token::Match(tok->linkAt(1)->tokAt(-2), "&& %str% )")))
tok = tok->linkAt(1);

if (Token::simpleMatch(tok, ". substr (") && Token::Match(tok->tokAt(3)->nextArgument(), "%num% )")) {
const MathLib::biguint clen = MathLib::toBigUNumber(tok->linkAt(2)->strAt(-1));
Expand Down
8 changes: 4 additions & 4 deletions lib/checkuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
}

// goto the {
tok = tok->next()->link()->next();
tok = tok->linkAt(1)->next();

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

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,8 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
} else if (Token::Match(tok, "[(,] & %var% [,)]")) {
variables.eraseAll(tok->tokAt(2)->varId());
} else if (Token::Match(tok, "[(,] (") &&
Token::Match(tok->next()->link(), ") %var% [,)[]")) {
variables.use(tok->next()->link()->next()->varId(), tok); // use = read + write
Token::Match(tok->linkAt(1), ") %var% [,)[]")) {
variables.use(tok->linkAt(1)->next()->varId(), tok); // use = read + write
} else if (Token::Match(tok, "[(,] *| *| %var%")) {
const Token* vartok = tok->next();
while (vartok->str() == "*")
Expand Down
8 changes: 4 additions & 4 deletions lib/forwardanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,13 +656,13 @@ namespace {
return Break();
}
} else if (tok->isControlFlowKeyword() && Token::Match(tok, "if|while|for (") &&
Token::simpleMatch(tok->next()->link(), ") {")) {
Token::simpleMatch(tok->linkAt(1), ") {")) {
if ((settings.vfOptions.maxForwardBranches > 0) && (++branchCount > settings.vfOptions.maxForwardBranches)) {
// TODO: should be logged on function-level instead of file-level
reportError(Severity::information, "normalCheckLevelMaxBranches", "Limiting analysis of branches. Use --check-level=exhaustive to analyze all branches.");
return Break(Analyzer::Terminate::Bail);
}
Token* endCond = tok->next()->link();
Token* endCond = tok->linkAt(1);
Token* endBlock = endCond->next()->link();
Token* condTok = getCondTok(tok);
Token* initTok = getInitTok(tok);
Expand Down Expand Up @@ -769,7 +769,7 @@ namespace {
}
}
} else if (Token::simpleMatch(tok, "try {")) {
Token* endBlock = tok->next()->link();
Token* endBlock = tok->linkAt(1);
ForwardTraversal tryTraversal = fork();
tryTraversal.updateScope(endBlock, depth - 1);
bool bail = tryTraversal.actions.isModified();
Expand All @@ -792,7 +792,7 @@ namespace {
return Break();
tok = endBlock;
} else if (Token::simpleMatch(tok, "do {")) {
Token* endBlock = tok->next()->link();
Token* endBlock = tok->linkAt(1);
Token* condTok = Token::simpleMatch(endBlock, "} while (") ? endBlock->tokAt(2)->astOperand2() : nullptr;
if (updateLoop(end, endBlock, condTok) == Progress::Break)
return Break();
Expand Down
6 changes: 3 additions & 3 deletions lib/pathanalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ PathAnalysis::Progress PathAnalysis::forwardRange(const Token* startToken, const
if (Token::simpleMatch(tok, "} else {")) {
tok = tok->linkAt(2);
}
} else if (Token::Match(tok, "if|while|for (") && Token::simpleMatch(tok->next()->link(), ") {")) {
const Token * endCond = tok->next()->link();
} else if (Token::Match(tok, "if|while|for (") && Token::simpleMatch(tok->linkAt(1), ") {")) {
const Token * endCond = tok->linkAt(1);
const Token * endBlock = endCond->next()->link();
const Token * condTok = getCondTok(tok);
if (!condTok)
continue;
// Traverse condition
if (forwardRange(tok->next(), tok->next()->link(), info, f) == Progress::Break)
if (forwardRange(tok->next(), tok->linkAt(1), info, f) == Progress::Break)
return Progress::Break;
Info i = info;
i.known = false;
Expand Down
Loading