Fix more moves
This commit is fixing coverity issues reported for copy in stead of
move.
Tested: redfish service validator passes
Change-Id: I97e755830f28390e7c4bfaba6f3f947898a21423
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/http/http_request.hpp b/http/http_request.hpp
index c2778ca..25fd5b3 100644
--- a/http/http_request.hpp
+++ b/http/http_request.hpp
@@ -40,7 +40,7 @@
std::shared_ptr<persistent_data::UserSession> session;
std::string userRole;
- Request(Body reqIn, std::error_code& ec) : req(std::move(reqIn))
+ Request(Body&& reqIn, std::error_code& ec) : req(std::move(reqIn))
{
if (!setUrlInfo())
{
diff --git a/redfish-core/include/redfish_aggregator.hpp b/redfish-core/include/redfish_aggregator.hpp
index 26ff934..96be7e9 100644
--- a/redfish-core/include/redfish_aggregator.hpp
+++ b/redfish-core/include/redfish_aggregator.hpp
@@ -596,7 +596,7 @@
// Create a copy of thisReq so we we can still locally process the req
std::error_code ec;
- auto localReq = std::make_shared<crow::Request>(thisReq.req, ec);
+ auto localReq = std::make_shared<crow::Request>(thisReq.copy());
if (ec)
{
BMCWEB_LOG_ERROR("Failed to create copy of request");
diff --git a/redfish-core/include/utils/query_param.hpp b/redfish-core/include/utils/query_param.hpp
index 33c6ff9..ca2822d 100644
--- a/redfish-core/include/utils/query_param.hpp
+++ b/redfish-core/include/utils/query_param.hpp
@@ -926,19 +926,19 @@
if (object != nullptr)
{
BMCWEB_LOG_DEBUG("Current JSON is an object");
- auto it = currRoot.begin();
- while (it != currRoot.end())
+ auto it = object->begin();
+ while (it != object->end())
{
auto nextIt = std::next(it);
- BMCWEB_LOG_DEBUG("key={}", it.key());
- const SelectTrieNode* nextNode = currNode.find(it.key());
+ BMCWEB_LOG_DEBUG("key={}", it->first);
+ const SelectTrieNode* nextNode = currNode.find(it->first);
// Per the Redfish spec section 7.3.3, the service shall select
// certain properties as if $select was omitted. This applies to
// every TrieNode that contains leaves and the root.
constexpr std::array<std::string_view, 5> reservedProperties = {
"@odata.id", "@odata.type", "@odata.context", "@odata.etag",
"error"};
- bool reserved = std::ranges::find(reservedProperties, it.key()) !=
+ bool reserved = std::ranges::find(reservedProperties, it->first) !=
reservedProperties.end();
if (reserved || (nextNode != nullptr && nextNode->isSelected()))
{
@@ -947,13 +947,13 @@
}
if (nextNode != nullptr)
{
- BMCWEB_LOG_DEBUG("Recursively select: {}", it.key());
- recursiveSelect(*it, *nextNode);
+ BMCWEB_LOG_DEBUG("Recursively select: {}", it->first);
+ recursiveSelect(it->second, *nextNode);
it = nextIt;
continue;
}
- BMCWEB_LOG_DEBUG("{} is getting removed!", it.key());
- it = currRoot.erase(it);
+ BMCWEB_LOG_DEBUG("{} is getting removed!", it->first);
+ it = object->erase(it);
}
}
nlohmann::json::array_t* array =
diff --git a/redfish-core/lib/metric_report_definition.hpp b/redfish-core/lib/metric_report_definition.hpp
index 06e8075..022e625 100644
--- a/redfish-core/lib/metric_report_definition.hpp
+++ b/redfish-core/lib/metric_report_definition.hpp
@@ -600,7 +600,7 @@
"MetricReportDefinitionType");
return false;
}
- args.reportingType = dbusReportingType;
+ args.reportingType = std::move(dbusReportingType);
}
if (reportUpdatesStr)
@@ -612,7 +612,7 @@
"ReportUpdates");
return false;
}
- args.reportUpdates = dbusReportUpdates;
+ args.reportUpdates = std::move(dbusReportUpdates);
}
if (appendLimit)
diff --git a/redfish-core/src/error_message_utils.cpp b/redfish-core/src/error_message_utils.cpp
index ae7829a..04ba41a 100644
--- a/redfish-core/src/error_message_utils.cpp
+++ b/redfish-core/src/error_message_utils.cpp
@@ -61,35 +61,46 @@
void moveErrorsToErrorJson(nlohmann::json& target, nlohmann::json& source)
{
- if (!source.is_object())
+ nlohmann::json::object_t* sourceObj =
+ source.get_ptr<nlohmann::json::object_t*>();
+ if (sourceObj == nullptr)
{
return;
}
- auto errorIt = source.find("error");
- if (errorIt == source.end())
+
+ nlohmann::json::object_t::iterator errorIt = sourceObj->find("error");
+ if (errorIt == sourceObj->end())
{
// caller puts error message in root
messages::addMessageToErrorJson(target, source);
source.clear();
return;
}
- auto extendedInfoIt = errorIt->find(messages::messageAnnotation);
- if (extendedInfoIt == errorIt->end())
+ nlohmann::json::object_t* errorObj =
+ errorIt->second.get_ptr<nlohmann::json::object_t*>();
+ if (errorObj == nullptr)
+ {
+ return;
+ }
+
+ nlohmann::json::object_t::iterator extendedInfoIt =
+ errorObj->find(messages::messageAnnotation);
+ if (extendedInfoIt == errorObj->end())
{
return;
}
const nlohmann::json::array_t* extendedInfo =
- (*extendedInfoIt).get_ptr<const nlohmann::json::array_t*>();
+ extendedInfoIt->second.get_ptr<const nlohmann::json::array_t*>();
if (extendedInfo == nullptr)
{
- source.erase(errorIt);
+ sourceObj->erase(errorIt);
return;
}
for (const nlohmann::json& message : *extendedInfo)
{
addMessageToErrorJson(target, message);
}
- source.erase(errorIt);
+ sourceObj->erase(errorIt);
}
void addMessageToJsonRoot(nlohmann::json& target, const nlohmann::json& message)
diff --git a/src/dbus_utility.cpp b/src/dbus_utility.cpp
index 54eb0aa..ecd0dec 100644
--- a/src/dbus_utility.cpp
+++ b/src/dbus_utility.cpp
@@ -108,7 +108,7 @@
const MapperGetSubTreeResponse&)>&& callback)
{
dbus::utility::async_method_call(
- [callback{std::move(callback)}](
+ [callback = std::move(callback)](
const boost::system::error_code& ec,
const MapperGetSubTreeResponse& subtree) { callback(ec, subtree); },
"xyz.openbmc_project.ObjectMapper",
@@ -124,7 +124,7 @@
const MapperGetSubTreePathsResponse&)>&& callback)
{
dbus::utility::async_method_call(
- [callback{std::move(callback)}](
+ [callback = std::move(callback)](
const boost::system::error_code& ec,
const MapperGetSubTreePathsResponse& subtreePaths) {
callback(ec, subtreePaths);
@@ -143,7 +143,7 @@
const MapperGetSubTreeResponse&)>&& callback)
{
dbus::utility::async_method_call(
- [callback{std::move(callback)}](
+ [callback = std::move(callback)](
const boost::system::error_code& ec,
const MapperGetSubTreeResponse& subtree) { callback(ec, subtree); },
"xyz.openbmc_project.ObjectMapper",
@@ -160,7 +160,7 @@
const MapperGetSubTreePathsResponse&)>&& callback)
{
dbus::utility::async_method_call(
- [callback{std::move(callback)}](
+ [callback = std::move(callback)](
const boost::system::error_code& ec,
const MapperGetSubTreePathsResponse& subtreePaths) {
callback(ec, subtreePaths);
@@ -180,7 +180,7 @@
const MapperGetSubTreeResponse&)>&& callback)
{
dbus::utility::async_method_call(
- [callback{std::move(callback)}](
+ [callback = std::move(callback)](
const boost::system::error_code& ec,
const MapperGetSubTreeResponse& subtree) { callback(ec, subtree); },
"xyz.openbmc_project.ObjectMapper",
@@ -198,7 +198,7 @@
const MapperGetSubTreePathsResponse&)>&& callback)
{
dbus::utility::async_method_call(
- [callback{std::move(callback)}](
+ [callback = std::move(callback)](
const boost::system::error_code& ec,
const MapperGetSubTreePathsResponse& subtreePaths) {
callback(ec, subtreePaths);
@@ -215,8 +215,8 @@
const MapperGetObject&)>&& callback)
{
dbus::utility::async_method_call(
- [callback{std::move(callback)}](const boost::system::error_code& ec,
- const MapperGetObject& object) {
+ [callback = std::move(callback)](const boost::system::error_code& ec,
+ const MapperGetObject& object) {
callback(ec, object);
},
"xyz.openbmc_project.ObjectMapper",
@@ -240,8 +240,8 @@
const ManagedObjectType&)>&& callback)
{
dbus::utility::async_method_call(
- [callback{std::move(callback)}](const boost::system::error_code& ec,
- const ManagedObjectType& objects) {
+ [callback = std::move(callback)](const boost::system::error_code& ec,
+ const ManagedObjectType& objects) {
callback(ec, objects);
},
service, path, "org.freedesktop.DBus.ObjectManager",