| 629 | } |
| 630 | |
| 631 | bool CheckNullPointer::analyseWholeProgram(const CTU::FileInfo &ctu, const std::list<const Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger) |
| 632 | { |
| 633 | (void)settings; |
| 634 | |
| 635 | CheckNullPointerImpl dummy(nullptr, settings, errorLogger); |
| 636 | dummy. |
| 637 | logChecker("CheckNullPointer::analyseWholeProgram"); |
| 638 | |
| 639 | if (fileInfo.empty()) |
| 640 | return false; |
| 641 | |
| 642 | const std::map<std::string, std::list<const CTU::FileInfo::CallBase *>> callsMap = ctu.getCallsMap(); |
| 643 | |
| 644 | bool foundErrors = false; |
| 645 | |
| 646 | for (const Check::FileInfo* fi1 : fileInfo) { |
| 647 | const auto *fi = dynamic_cast<const MyFileInfo*>(fi1); |
| 648 | if (!fi) |
| 649 | continue; |
| 650 | for (const CTU::FileInfo::UnsafeUsage &unsafeUsage : fi->unsafeUsage) { |
| 651 | for (int warning = 0; warning <= 1; warning++) { |
| 652 | if (warning == 1 && !settings.severity.isEnabled(Severity::warning)) |
| 653 | break; |
| 654 | |
| 655 | ValueFlow::Value::UnknownFunctionReturn unknownFunctionReturn = ValueFlow::Value::UnknownFunctionReturn::no; |
| 656 | std::list<ErrorMessage::FileLocation> locationList = |
| 657 | CTU::FileInfo::getErrorPath(CTU::FileInfo::InvalidValueType::null, |
| 658 | unsafeUsage, |
| 659 | callsMap, |
| 660 | "Dereferencing argument ARG that is null", |
| 661 | nullptr, |
| 662 | warning, |
| 663 | settings.maxCtuDepth, |
| 664 | &unknownFunctionReturn); |
| 665 | if (locationList.empty()) |
| 666 | continue; |
| 667 | |
| 668 | std::string id = "ctunullpointer"; |
| 669 | std::string message = "Null pointer dereference: " + unsafeUsage.myArgumentName; |
| 670 | if (unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfMemory) { |
| 671 | id += "OutOfMemory"; |
| 672 | message = "If memory allocation fails, then there is a possible null pointer dereference: " + unsafeUsage.myArgumentName; |
| 673 | } else if (unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfResources) { |
| 674 | id += "OutOfResources"; |
| 675 | message = "If resource allocation fails, then there is a possible null pointer dereference: " + unsafeUsage.myArgumentName; |
| 676 | } |
| 677 | |
| 678 | ErrorMessage errmsg(std::move(locationList), |
| 679 | fi->file0, |
| 680 | warning ? Severity::warning : Severity::error, |
| 681 | message, |
| 682 | std::move(id), |
| 683 | CWE_NULL_POINTER_DEREFERENCE, Certainty::normal); |
| 684 | errorLogger.reportErr(errmsg); |
| 685 | |
| 686 | foundErrors = true; |
| 687 | break; |
| 688 | } |
nothing calls this directly
no test coverage detected