pldmd : 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: Ibb10a86bbd2f1044b79b965dfc865b6bf19075fc
Signed-off-by: Pavithra Barithaya <pavithrabarithaya07@gmail.com>
diff --git a/pldmd/pldmd.cpp b/pldmd/pldmd.cpp
index 202f794..7a62584 100644
--- a/pldmd/pldmd.cpp
+++ b/pldmd/pldmd.cpp
@@ -138,7 +138,7 @@
{
uint8_t completion_code = PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
response.resize(sizeof(pldm_msg_hdr));
- auto responseHdr = reinterpret_cast<pldm_msg_hdr*>(response.data());
+ auto responseHdr = new (response.data()) pldm_msg_hdr;
pldm_header_info header{};
header.msg_type = PLDM_RESPONSE;
header.instance = hdrFields.instance;