Skip to content

Commit c7f882e

Browse files
committed
refactor
1 parent 6c65a0d commit c7f882e

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

lib/checknullpointer.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,11 +676,9 @@ bool CheckNullPointer::analyseWholeProgram(const CTU::FileInfo &ctu, const std::
676676
std::string message = "Null pointer dereference: " + unsafeUsage.myArgumentName;
677677
if (unknownFunctionReturn == (std::uint8_t)ValueFlow::Value::UnknownFunctionReturn::outOfMemory) {
678678
id += "OutOfMemory";
679-
warning = 1;
680679
message = "If memory allocation fails, then there is a possible null pointer dereference: " + unsafeUsage.myArgumentName;
681680
} else if (unknownFunctionReturn == (std::uint8_t)ValueFlow::Value::UnknownFunctionReturn::outOfResources) {
682681
id += "OutOfResources";
683-
warning = 1;
684682
message = "If resource allocation fails, then there is a possible null pointer dereference: " + unsafeUsage.myArgumentName;
685683
}
686684

lib/ctu.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ static bool findPath(const std::string &callId,
522522
if (functionCall) {
523523
if (!warning && functionCall->warning)
524524
continue;
525+
if (!warning && functionCall->callArgValue.unknownFunctionReturn > 0)
526+
continue;
525527
switch (invalidValue) {
526528
case CTU::FileInfo::InvalidValueType::null:
527529
if (functionCall->callValueType != ValueFlow::Value::ValueType::INT || functionCall->callArgValue.value != 0)
@@ -569,9 +571,10 @@ std::list<ErrorMessage::FileLocation> CTU::FileInfo::getErrorPath(InvalidValueTy
569571
if (!findPath(unsafeUsage.myId, unsafeUsage.myArgNr, unsafeUsage.value, invalidValue, callsMap, path, 0, warning, maxCtuDepth))
570572
return {};
571573

572-
if (unknownFunctionReturn && path[0] && dynamic_cast<const CTU::FileInfo::FunctionCall *>(path[0])) {
573-
const auto* v = dynamic_cast<const CTU::FileInfo::FunctionCall *>(path[0]);
574-
*unknownFunctionReturn = v->callArgValue.unknownFunctionReturn;
574+
if (unknownFunctionReturn && path[0]) {
575+
const auto* functionCall = dynamic_cast<const CTU::FileInfo::FunctionCall *>(path[0]);
576+
if (functionCall)
577+
*unknownFunctionReturn = functionCall->callArgValue.unknownFunctionReturn;
575578
}
576579

577580
std::list<ErrorMessage::FileLocation> locationList;

0 commit comments

Comments
 (0)