Skip to content

Commit f400d04

Browse files
authored
valueflow.cpp: mitigated Coverity warnings in valueFlowUnknownFunctionReturn() (danmar#7088)
1 parent 8c2390e commit f400d04

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

lib/valueflow.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6964,18 +6964,19 @@ static void valueFlowUnknownFunctionReturn(TokenList& tokenlist, const Settings&
69646964
if (!tok->astParent() || tok->str() != "(" || !tok->previous()->isName())
69656965
continue;
69666966

6967-
if (settings.library.getAllocFuncInfo(tok->astOperand1()) && settings.library.returnValueType(tok->astOperand1()).find('*') != std::string::npos) {
6968-
// Allocation function that returns a pointer
6969-
ValueFlow::Value value(0);
6970-
value.setPossible();
6971-
value.errorPath.emplace_back(tok, "Assuming allocation function fails");
6972-
const auto* f = settings.library.getAllocFuncInfo(tok->astOperand1());
6973-
if (Library::ismemory(f->groupId))
6974-
value.unknownFunctionReturn = ValueFlow::Value::UnknownFunctionReturn::outOfMemory;
6975-
else
6976-
value.unknownFunctionReturn = ValueFlow::Value::UnknownFunctionReturn::outOfResources;
6977-
setTokenValue(tok, value, settings);
6978-
continue;
6967+
if (const auto* f = settings.library.getAllocFuncInfo(tok->astOperand1())) {
6968+
if (settings.library.returnValueType(tok->astOperand1()).find('*') != std::string::npos) {
6969+
// Allocation function that returns a pointer
6970+
ValueFlow::Value value(0);
6971+
value.setPossible();
6972+
value.errorPath.emplace_back(tok, "Assuming allocation function fails");
6973+
if (Library::ismemory(f->groupId))
6974+
value.unknownFunctionReturn = ValueFlow::Value::UnknownFunctionReturn::outOfMemory;
6975+
else
6976+
value.unknownFunctionReturn = ValueFlow::Value::UnknownFunctionReturn::outOfResources;
6977+
setTokenValue(tok, std::move(value), settings);
6978+
continue;
6979+
}
69796980
}
69806981

69816982
if (settings.checkUnknownFunctionReturn.find(tok->strAt(-1)) == settings.checkUnknownFunctionReturn.end())

0 commit comments

Comments
 (0)