MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / eraseIteratorOutOfBounds

Method eraseIteratorOutOfBounds

lib/checkstl.cpp:3358–3382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3356}
3357
3358void CheckStlImpl::eraseIteratorOutOfBounds()
3359{
3360 logChecker("CheckStl::eraseIteratorOutOfBounds");
3361 for (const Scope *function : mTokenizer->getSymbolDatabase()->functionScopes) {
3362 for (const Token *tok = function->bodyStart; tok != function->bodyEnd; tok = tok->next()) {
3363
3364 if (!tok->valueType())
3365 continue;
3366 const Library::Container* container = tok->valueType()->container;
3367 if (!container || !astIsLHS(tok) || !Token::simpleMatch(tok->astParent(), "."))
3368 continue;
3369 const Token* const ftok = tok->astParent()->astOperand2();
3370 const Library::Container::Action action = container->getAction(ftok->str());
3371 if (action != Library::Container::Action::ERASE)
3372 continue;
3373 const std::vector<const Token*> args = getArguments(ftok);
3374 if (args.size() != 1) // TODO: check range overload
3375 continue;
3376
3377 const ValueFlow::Value* sizeVal = tok->getKnownValue(ValueFlow::Value::ValueType::CONTAINER_SIZE);
3378 if (const ValueFlow::Value* errVal = getOOBIterValue(args[0], sizeVal))
3379 eraseIteratorOutOfBoundsError(ftok, args[0], errVal);
3380 }
3381 }
3382}
3383
3384static bool isMutex(const Variable* var)
3385{

Callers 1

runChecksMethod · 0.45

Calls 11

astIsLHSFunction · 0.85
getOOBIterValueFunction · 0.85
nextMethod · 0.80
astParentMethod · 0.80
astOperand2Method · 0.80
getActionMethod · 0.80
getKnownValueMethod · 0.80
simpleMatchFunction · 0.70
getArgumentsFunction · 0.70
strMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected