bkietz commented on code in PR #44468:
URL: https://github.com/apache/arrow/pull/44468#discussion_r1806657258


##########
cpp/src/arrow/util/ubsan.h:
##########
@@ -63,7 +63,7 @@ inline std::enable_if_t<std::is_trivially_copyable_v<T>, T> 
SafeLoadAs(
 template <typename T>
 inline std::enable_if_t<std::is_trivially_copyable_v<T>, T> SafeLoad(const T* 
unaligned) {
   std::remove_const_t<T> ret;
-  std::memcpy(&ret, unaligned, sizeof(T));
+  std::memcpy(&ret, reinterpret_cast<const void*>(unaligned), sizeof(T));

Review Comment:
   static cast is more strict and therefore preferable here; reinterpret cast 
should only be used when the type system is being circumvented somehow (eg 
[type 
punning](https://github.com/apache/arrow/blob/main/cpp/src/arrow/util/aligned_storage.h#L36))
   
   The [legal operations for reinterpret 
cast](https://timsong-cpp.github.io/cppwp/n4868/expr.reinterpret.cast) don't 
include many of the things we use it for, but ... the type punning we do in 
arrow-c++ is not unique to this project.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to