libpldmresponder : 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: If96afcb2c9dbea8fb6815d74a2181ca9ed04903a
Signed-off-by: Pavithra Barithaya <pavithrabarithaya07@gmail.com>
diff --git a/libpldmresponder/bios.cpp b/libpldmresponder/bios.cpp
index 57668d8..1ad297c 100644
--- a/libpldmresponder/bios.cpp
+++ b/libpldmresponder/bios.cpp
@@ -120,7 +120,7 @@
constexpr auto timeInterface = "xyz.openbmc_project.Time.EpochTime";
constexpr auto bmcTimePath = "/xyz/openbmc_project/time/bmc";
Response response(sizeof(pldm_msg_hdr) + PLDM_GET_DATE_TIME_RESP_BYTES, 0);
- auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
+ auto responsePtr = new (response.data()) pldm_msg;
EpochTimeUS timeUsec;
try
@@ -246,7 +246,7 @@
Response response(sizeof(pldm_msg_hdr) +
PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES + table->size());
- auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
+ auto responsePtr = new (response.data()) pldm_msg;
rc = encode_get_bios_table_resp(
request->hdr.instance_id, PLDM_SUCCESS, 0 /* nxtTransferHandle */,
@@ -281,7 +281,7 @@
}
Response response(sizeof(pldm_msg_hdr) + PLDM_SET_BIOS_TABLE_RESP_BYTES);
- auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
+ auto responsePtr = new (response.data()) pldm_msg;
rc = encode_set_bios_table_resp(request->hdr.instance_id, PLDM_SUCCESS,
0 /* nxtTransferHandle */, responsePtr);
@@ -326,7 +326,7 @@
PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_MIN_RESP_BYTES +
entryLength,
0);
- auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
+ auto responsePtr = new (response.data()) pldm_msg;
rc = encode_get_bios_current_value_by_handle_resp(
request->hdr.instance_id, PLDM_SUCCESS, 0, PLDM_START_AND_END,
reinterpret_cast<const uint8_t*>(entry), entryLength, responsePtr);
@@ -358,7 +358,7 @@
Response response(
sizeof(pldm_msg_hdr) + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES, 0);
- auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
+ auto responsePtr = new (response.data()) pldm_msg;
encode_set_bios_attribute_current_value_resp(request->hdr.instance_id, rc,
0, responsePtr);