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

Method getUnsafeUsage

lib/ctu.cpp:477–500  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

475}
476
477std::list<CTU::FileInfo::UnsafeUsage> CTU::getUnsafeUsage(const Tokenizer &tokenizer, const Settings &settings, bool (*isUnsafeUsage)(const Settings &settings, const Token *argtok, CTU::FileInfo::Value *value))
478{
479 std::list<CTU::FileInfo::UnsafeUsage> unsafeUsage;
480
481 // Parse all functions in TU
482 const SymbolDatabase * const symbolDatabase = tokenizer.getSymbolDatabase();
483
484 for (const Scope &scope : symbolDatabase->scopeList) {
485 if (!scope.isExecutable() || scope.type != ScopeType::eFunction || !scope.function)
486 continue;
487 const Function *const function = scope.function;
488
489 // "Unsafe" functions unconditionally reads data before it is written..
490 for (int argnr = 0; argnr < function->argCount(); ++argnr) {
491 for (const std::pair<const Token *, CTU::FileInfo::Value> &v : getUnsafeFunction(settings, &scope, argnr, isUnsafeUsage)) {
492 const Token *tok = v.first;
493 const MathLib::bigint val = v.second.value;
494 unsafeUsage.emplace_back(CTU::getFunctionId(tokenizer, function), argnr+1, tok->str(), CTU::FileInfo::Location(tokenizer,tok), val);
495 }
496 }
497 }
498
499 return unsafeUsage;
500}
501
502static bool findPath(const std::string &callId,
503 nonneg int callArgNr,

Callers

nothing calls this directly

Calls 3

getUnsafeFunctionFunction · 0.85
LocationClass · 0.70
strMethod · 0.45

Tested by

no test coverage detected