From 01747de2e816341263abf762bbf3be9b57b66b88 Mon Sep 17 00:00:00 2001 From: ngb Date: Wed, 25 Nov 2026 03:30:30 +0530 Subject: [PATCH] GH-55763 : Use std::bit_cast in SafeCopy --- cpp/src/arrow/util/ubsan.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cpp/src/arrow/util/ubsan.h b/cpp/src/arrow/util/ubsan.h index 6c8a9812af29..ac6b98b1d1d1 100644 --- a/cpp/src/arrow/util/ubsan.h +++ b/cpp/src/arrow/util/ubsan.h @@ -22,6 +22,7 @@ #include #include #include +#include #include "arrow/util/aligned_storage.h" #include "arrow/util/macros.h" @@ -75,20 +76,17 @@ ARROW_FORCE_INLINE std::enable_if_t, T> SafeLoad return data; } + template ARROW_FORCE_INLINE std::enable_if_t && std::is_trivially_copyable_v && sizeof(T) == sizeof(U), U> SafeCopy(T value) { - using TypeU = std::remove_const_t; - arrow::internal::AlignedStorage raw_data; - std::memcpy(raw_data.get(), static_cast(&value), sizeof(T)); - auto data = *raw_data.get(); - raw_data.destroy(); - return data; + return std::bit_cast>(value); } + template ARROW_FORCE_INLINE std::enable_if_t, void> SafeStore( void* unaligned, T value) {