host-bmc: Migrate to placement_new from reinterpret casting
reinterpret_cast is prohibited by the C++ core guidelines because
it takes the behavior outside the language definition and gives
problems with type safety. Placement-new on the other-hand allows
to control the object storage while still properly instantiating
an object,keeping the behavior inside the C++ language
specification.
Change-Id: If8dcc8ebb592692110a7c96485021e0df660f576
Signed-off-by: Pavithra Barithaya <pavithrabarithaya07@gmail.com>
diff --git a/host-bmc/dbus_to_terminus_effecters.cpp b/host-bmc/dbus_to_terminus_effecters.cpp
index 54eb71f..5c2e0ee 100644
--- a/host-bmc/dbus_to_terminus_effecters.cpp
+++ b/host-bmc/dbus_to_terminus_effecters.cpp
@@ -484,7 +484,7 @@
size_t payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES - 1 +
getEffecterDataSize(dataSize);
requestMsg.resize(sizeof(pldm_msg_hdr) + payload_length);
- auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ auto request = new (requestMsg.data()) pldm_msg;
switch (dataSize)
{
case PLDM_EFFECTER_DATA_SIZE_UINT8:
@@ -605,7 +605,7 @@
sizeof(pldm_msg_hdr) + sizeof(effecterId) + sizeof(compEffCnt) +
sizeof(set_effecter_state_field) * compEffCnt,
0);
- auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ auto request = new (requestMsg.data()) pldm_msg;
auto rc = encode_set_state_effecter_states_req(
instanceId, effecterId, compEffCnt, stateField.data(), request);