@@ -945,42 +945,44 @@ void CheckBufferOverrun::checkScope_inner(const Token *tok, const ArrayInfo &arr
945945 const bool printWarning = _settings->isEnabled (Settings::WARNING);
946946 const bool printInconclusive = _settings->inconclusive ;
947947
948+ const Token *astParent = tok->astParent ();
949+
948950 if (tok->strAt (1 ) == " [" ) {
949951 valueFlowCheckArrayIndex (tok->next (), arrayInfo);
950952 }
951953
952- else if (printPortability && !tok->isCast () && tok-> astParent () && tok-> astParent () ->str () == " +" ) {
954+ else if (printPortability && !tok->isCast () && astParent && astParent->str () == " +" ) {
953955 // undefined behaviour: result of pointer arithmetic is out of bounds
954956 const Token *index;
955- if (tok == tok-> astParent () ->astOperand1 ())
956- index = tok-> astParent () ->astOperand2 ();
957+ if (tok == astParent->astOperand1 ())
958+ index = astParent->astOperand2 ();
957959 else
958- index = tok-> astParent () ->astOperand1 ();
960+ index = astParent->astOperand1 ();
959961 if (index) {
960962 const ValueFlow::Value *value = index->getValueGE (arrayInfo.num (0 ) + 1U , _settings);
961963 if (!value)
962964 value = index->getValueLE (-1 , _settings);
963965 if (value)
964- pointerOutOfBoundsError (tok-> astParent () , index, value->intvalue );
966+ pointerOutOfBoundsError (astParent, index, value->intvalue );
965967 }
966968 }
967969
968- else if (printPortability && tok-> astParent () && tok-> astParent () ->str () == " -" ) {
970+ else if (printPortability && astParent && astParent->str () == " -" ) {
969971 const Variable *var = symbolDatabase->getVariableFromVarId (arrayInfo.declarationId ());
970972 if (var && var->isArray ()) {
971- const Token *index = tok-> astParent () ->astOperand2 ();
973+ const Token *index = astParent->astOperand2 ();
972974 const ValueFlow::Value *value = index ? index->getValueGE (1 ,_settings) : nullptr ;
973975 if (index && !value)
974976 value = index->getValueLE (-1 - arrayInfo.num (0 ), _settings);
975977 if (value)
976- pointerOutOfBoundsError (tok-> astParent () , index, value->intvalue );
978+ pointerOutOfBoundsError (astParent, index, value->intvalue );
977979 }
978980 }
979981
980982 if (!tok->scope ()->isExecutable ()) // No executable code outside of executable scope - continue to increase performance
981983 return ;
982984
983- const Token* tok2 = tok-> astParent () ;
985+ const Token* tok2 = astParent;
984986 if (tok2) {
985987 while (tok2->astParent () && !Token::Match (tok2->astParent (), " [,(]" ))
986988 tok2 = tok2->astParent ();
0 commit comments