From c926f011abc7dbe2d58d68fe05d50977eb545803 Mon Sep 17 00:00:00 2001 From: Nazarov Konstantin Date: Tue, 29 Mar 2022 18:58:09 +0300 Subject: [PATCH] issues 256,257 Signed-off-by: Nazarov Konstantin --- libpandabase/utils/bit_utils.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libpandabase/utils/bit_utils.h b/libpandabase/utils/bit_utils.h index e36451d..fa5489d 100644 --- a/libpandabase/utils/bit_utils.h +++ b/libpandabase/utils/bit_utils.h @@ -26,6 +26,8 @@ #include #include +#include + #define panda_bit_utils_ctz __builtin_ctz // NOLINT(cppcoreguidelines-macro-usage) #define panda_bit_utils_ctzll __builtin_ctzll // NOLINT(cppcoreguidelines-macro-usage) @@ -292,7 +294,9 @@ inline To bit_cast(const From &src) noexcept // NOLINT(readability-identifier-n { static_assert(sizeof(To) == sizeof(From), "size of the types must be equal"); To dst; - memcpy(&dst, &src, sizeof(To)); + if (memcpy_s(&dst, sizeof(To), &src, sizeof(To)) != EOK) { + UNREACHABLE(); + } return dst; } @@ -301,7 +305,9 @@ inline To down_cast(const From &src) noexcept // NOLINT(readability-identifier- { static_assert(sizeof(To) <= sizeof(From), "size of the types must be lesser"); To dst; - memcpy(&dst, &src, sizeof(To)); + if (memcpy_s(&dst, sizeof(To), &src, sizeof(To)) != EOK) { + UNREACHABLE(); + } return dst; }