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

Method getErrorPath

lib/ctu.cpp:576–622  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

574}
575
576std::list<ErrorMessage::FileLocation> CTU::FileInfo::getErrorPath(InvalidValueType invalidValue,
577 const CTU::FileInfo::UnsafeUsage &unsafeUsage,
578 const std::map<std::string, std::list<const CTU::FileInfo::CallBase *>> &callsMap,
579 const char info[],
580 const FunctionCall ** const functionCallPtr,
581 bool warning,
582 int maxCtuDepth,
583 ValueFlow::Value::UnknownFunctionReturn *unknownFunctionReturn)
584{
585 const CTU::FileInfo::CallBase *path[10] = {nullptr};
586
587 if (!findPath(unsafeUsage.myId, unsafeUsage.myArgNr, unsafeUsage.value, invalidValue, callsMap, path, 0, warning, maxCtuDepth))
588 return {};
589
590 if (unknownFunctionReturn && path[0]) {
591 const auto* functionCall = dynamic_cast<const CTU::FileInfo::FunctionCall *>(path[0]);
592 if (functionCall)
593 *unknownFunctionReturn = functionCall->callArgValue.unknownFunctionReturn;
594 }
595
596 std::list<ErrorMessage::FileLocation> locationList;
597
598 const std::string value1 = getInvalidValueString(invalidValue);
599
600 for (int index = 9; index >= 0; index--) {
601 if (!path[index])
602 continue;
603
604 const auto *functionCall = dynamic_cast<const CTU::FileInfo::FunctionCall *>(path[index]);
605
606 if (functionCall) {
607 if (functionCallPtr)
608 *functionCallPtr = functionCall;
609 std::copy(functionCall->callValuePath.cbegin(), functionCall->callValuePath.cend(), std::back_inserter(locationList));
610 }
611
612 std::string info_s = "Calling function " + path[index]->callFunctionName + ", " + std::to_string(path[index]->callArgNr) + getOrdinalText(path[index]->callArgNr) + " argument is " + value1;
613 ErrorMessage::FileLocation fileLoc(path[index]->location.fileName, std::move(info_s), path[index]->location.lineNumber, path[index]->location.column);
614 locationList.push_back(std::move(fileLoc));
615 }
616
617 std::string info_s = replaceStr(info, "ARG", unsafeUsage.myArgumentName);
618 ErrorMessage::FileLocation fileLoc2(unsafeUsage.location.fileName, std::move(info_s), unsafeUsage.location.lineNumber, unsafeUsage.location.column);
619 locationList.push_back(std::move(fileLoc2));
620
621 return locationList;
622}

Callers

nothing calls this directly

Calls 6

findPathFunction · 0.85
getInvalidValueStringFunction · 0.85
copyFunction · 0.85
getOrdinalTextFunction · 0.85
replaceStrFunction · 0.85
push_backMethod · 0.45

Tested by

no test coverage detected