From 927fc1f8601bf5d3e5a98085bcd079e2094078ad Mon Sep 17 00:00:00 2001 From: "Kevin F. Ortega" Date: Wed, 4 Nov 2020 17:27:37 -0800 Subject: [PATCH] using memcpy instead of statements with undefined behavior --- Fw/Types/Serializable.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Fw/Types/Serializable.cpp b/Fw/Types/Serializable.cpp index 551b613ce5..33a8e1aa68 100644 --- a/Fw/Types/Serializable.cpp +++ b/Fw/Types/Serializable.cpp @@ -191,8 +191,7 @@ namespace Fw { SerializeStatus SerializeBufferBase::serialize(F64 val) { // floating point values need to be byte-swapped as well, so copy to U64 and use that routine U64 u64Val; - - *reinterpret_cast(&u64Val) = val; + (void) memcpy(&u64Val, &val, sizeof(val)); return this->serialize(u64Val); } @@ -203,8 +202,7 @@ namespace Fw { // floating point values need to be byte-swapped as well, so copy to U32 and use that routine U32 u32Val; - - *reinterpret_cast(&u32Val) = val; + (void) memcpy(&u32Val, &val, sizeof(val)); return this->serialize(u32Val); } @@ -446,9 +444,8 @@ namespace Fw { if (stat != FW_SERIALIZE_OK) { return stat; } - // copy to argument - val = *reinterpret_cast(&tempVal); + (void) memcpy(&val, &tempVal, (NATIVE_UINT_TYPE)sizeof(val)); return FW_SERIALIZE_OK; } @@ -487,9 +484,7 @@ namespace Fw { if (stat != FW_SERIALIZE_OK) { return stat; } - - // copy to argument - val = *reinterpret_cast(&tempVal); + (void) memcpy(&val, &tempVal, sizeof(val)); return FW_SERIALIZE_OK; }