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

Function findPath

lib/ctu.cpp:502–560  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

500}
501
502static bool findPath(const std::string &callId,
503 nonneg int callArgNr,
504 MathLib::bigint unsafeValue,
505 CTU::FileInfo::InvalidValueType invalidValue,
506 const std::map<std::string, std::list<const CTU::FileInfo::CallBase *>> &callsMap,
507 const CTU::FileInfo::CallBase *path[10],
508 int index,
509 bool warning,
510 int maxCtuDepth)
511{
512 if (index >= maxCtuDepth)
513 return false; // TODO: add bailout message?
514
515 const auto it = callsMap.find(callId);
516 if (it == callsMap.end())
517 return false;
518
519 for (const CTU::FileInfo::CallBase *c : it->second) {
520 if (c->callArgNr != callArgNr)
521 continue;
522
523 const auto *functionCall = dynamic_cast<const CTU::FileInfo::FunctionCall *>(c);
524 if (functionCall) {
525 if (!warning && functionCall->warning)
526 continue;
527 if (!warning && functionCall->callArgValue.unknownFunctionReturn != ValueFlow::Value::UnknownFunctionReturn::no)
528 continue;
529 switch (invalidValue) {
530 case CTU::FileInfo::InvalidValueType::null:
531 if (functionCall->callValueType != ValueFlow::Value::ValueType::INT || functionCall->callArgValue.value != 0)
532 continue;
533 break;
534 case CTU::FileInfo::InvalidValueType::uninit:
535 if (functionCall->callValueType != ValueFlow::Value::ValueType::UNINIT)
536 continue;
537 break;
538 case CTU::FileInfo::InvalidValueType::bufferOverflow:
539 if (functionCall->callValueType != ValueFlow::Value::ValueType::BUFFER_SIZE)
540 continue;
541 if (unsafeValue < 0 || (unsafeValue >= functionCall->callArgValue.value && functionCall->callArgValue.value >= 0))
542 break;
543 continue;
544 }
545 path[index] = functionCall;
546 return true;
547 }
548
549 const auto *nestedCall = dynamic_cast<const CTU::FileInfo::NestedCall *>(c);
550 if (!nestedCall)
551 continue;
552
553 if (findPath(nestedCall->myId, nestedCall->myArgNr, unsafeValue, invalidValue, callsMap, path, index + 1, warning, maxCtuDepth)) {
554 path[index] = nestedCall;
555 return true;
556 }
557 }
558
559 return false;

Callers 2

getPathMethod · 0.85
getErrorPathMethod · 0.85

Calls 2

findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected