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>
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index fbc89a0..4f44b5a 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -2209,6 +2209,7 @@
                                       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 @@
     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;