fw-update : 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: Id5d75d41a83fbbae109506a8059e756596ba1cbc
Signed-off-by: Pavithra Barithaya <pavithrabarithaya07@gmail.com>
diff --git a/fw-update/update_manager.cpp b/fw-update/update_manager.cpp
index 2567996..66539d5 100644
--- a/fw-update/update_manager.cpp
+++ b/fw-update/update_manager.cpp
@@ -239,7 +239,7 @@
}
else
{
- auto ptr = reinterpret_cast<pldm_msg*>(response.data());
+ auto ptr = new (response.data()) pldm_msg;
auto rc = encode_cc_only_resp(
request->hdr.instance_id, request->hdr.type,
request->hdr.command, PLDM_ERROR_INVALID_DATA, ptr);
@@ -248,7 +248,7 @@
}
else
{
- auto ptr = reinterpret_cast<pldm_msg*>(response.data());
+ auto ptr = new (response.data()) pldm_msg;
auto rc = encode_cc_only_resp(request->hdr.instance_id,
request->hdr.type, +request->hdr.command,
PLDM_FWUP_COMMAND_NOT_EXPECTED, ptr);