summaryrefslogtreecommitdiff
path: root/redfish-core
diff options
context:
space:
mode:
authorAlexander Hansen <alexander.hansen@9elements.com>2024-03-08 19:04:54 +0300
committerAlexander Hansen <alexander.hansen@9elements.com>2024-03-11 11:48:39 +0300
commit6f4bd2904fd231c90ee86040f067018088097715 (patch)
treec6f84b259aade919f5b87b91b56c4780b8e0e1cf /redfish-core
parente715d14b258a764f0e41559fe4a5e9f7d2efe314 (diff)
downloadbmcweb-6f4bd2904fd231c90ee86040f067018088097715.tar.xz
fix usage of std::ranges::replace_copy
As hinted at in the usage example [1], the destination range must have sufficient size to contain the elements. If the destination range has size 0, then it will be empty after the function call. Then the "Name" property in powersupply json will be "" and there will only be one powersupply because of the deduplication code. Tested: Powersupplies appear as usual References: [1] https://en.cppreference.com/w/cpp/algorithm/ranges/replace_copy Change-Id: I81dd21a2dd6eb9b29a67007d6d6229d3a752690f Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
Diffstat (limited to 'redfish-core')
-rw-r--r--redfish-core/lib/sensors.hpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index fbc89a0831..4f44b5af90 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -2209,6 +2209,7 @@ inline nlohmann::json& getPowerSupply(nlohmann::json& powerSupplyArray,
const std::string& chassisId)
{
std::string nameS;
+ nameS.resize(inventoryItem.name.size());
std::ranges::replace_copy(inventoryItem.name, nameS.begin(), '_', ' ');
// Check if matching PowerSupply object already exists in JSON array
for (nlohmann::json& powerSupply : powerSupplyArray)
@@ -2237,6 +2238,7 @@ inline nlohmann::json& getPowerSupply(nlohmann::json& powerSupplyArray,
url.set_fragment(("/PowerSupplies"_json_pointer).to_string());
powerSupply["@odata.id"] = std::move(url);
std::string escaped;
+ escaped.resize(inventoryItem.name.size());
std::ranges::replace_copy(inventoryItem.name, escaped.begin(), '_', ' ');
powerSupply["Name"] = std::move(escaped);
powerSupply["Manufacturer"] = inventoryItem.manufacturer;