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

Method knownEmptyContainer

lib/checkstl.cpp:3270–3311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3268}
3269
3270void CheckStlImpl::knownEmptyContainer()
3271{
3272 if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("knownEmptyContainer"))
3273 return;
3274 logChecker("CheckStl::knownEmptyContainer"); // style
3275 for (const Scope *function : mTokenizer->getSymbolDatabase()->functionScopes) {
3276 for (const Token *tok = function->bodyStart; tok != function->bodyEnd; tok = tok->next()) {
3277
3278 if (!Token::Match(tok, "%name% ( !!)"))
3279 continue;
3280
3281 // Parse range-based for loop
3282 if (tok->str() == "for") {
3283 if (!Token::simpleMatch(tok->linkAt(1), ") {"))
3284 continue;
3285 const Token *splitTok = tok->next()->astOperand2();
3286 if (!Token::simpleMatch(splitTok, ":"))
3287 continue;
3288 const Token* contTok = splitTok->astOperand2();
3289 if (!isKnownEmptyContainer(contTok))
3290 continue;
3291 knownEmptyContainerError(contTok, "");
3292 } else {
3293 const std::vector<const Token *> args = getArguments(tok);
3294 if (args.empty())
3295 continue;
3296
3297 for (int argnr = 1; argnr <= args.size(); ++argnr) {
3298 const Library::ArgumentChecks::IteratorInfo *i = mSettings.library.getArgIteratorInfo(tok, argnr);
3299 if (!i)
3300 continue;
3301 const Token * const argTok = args[argnr - 1];
3302 if (!isKnownEmptyContainer(argTok))
3303 continue;
3304 knownEmptyContainerError(argTok, tok->str());
3305 break;
3306
3307 }
3308 }
3309 }
3310 }
3311}
3312
3313void CheckStlImpl::eraseIteratorOutOfBoundsError(const Token *ftok, const Token* itertok, const ValueFlow::Value* val)
3314{

Callers 1

runChecksMethod · 0.80

Calls 11

isKnownEmptyContainerFunction · 0.85
isPremiumEnabledMethod · 0.80
nextMethod · 0.80
linkAtMethod · 0.80
astOperand2Method · 0.80
simpleMatchFunction · 0.70
getArgumentsFunction · 0.70
isEnabledMethod · 0.45
strMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected