save-buffer commented on a change in pull request #11789:
URL: https://github.com/apache/arrow/pull/11789#discussion_r758634721



##########
File path: cpp/src/arrow/util/ubsan.h
##########
@@ -60,6 +60,14 @@ inline typename std::enable_if<std::is_trivial<T>::value, 
T>::type SafeLoadAs(
   return ret;

Review comment:
       you could probably make non-length SafeLoadAs call SafeLoadAs with 
`sizeof(T)` as `length`

##########
File path: cpp/src/arrow/util/ubsan.h
##########
@@ -68,6 +76,14 @@ inline typename std::enable_if<std::is_trivial<T>::value, 
T>::type SafeLoad(
   return ret;
 }
 
+template <typename T>
+inline typename std::enable_if<std::is_trivial<T>::value, T>::type SafeLoad(
+    const T* unaligned, uint32_t length) {

Review comment:
       nit: I think renaming `length` to `num_bytes` would be good (and same 
with the other function)

##########
File path: cpp/src/arrow/util/ubsan.h
##########
@@ -60,6 +60,14 @@ inline typename std::enable_if<std::is_trivial<T>::value, 
T>::type SafeLoadAs(
   return ret;
 }
 
+template <typename T>
+inline typename std::enable_if<std::is_trivial<T>::value, T>::type SafeLoadAs(
+    const uint8_t* unaligned, uint32_t length) {
+  typename std::remove_const<T>::type ret;
+  std::memcpy(&ret, unaligned, length);

Review comment:
       Might be a good idea to explain the difference between with/without 
length in a comment here, in case someone tries to reuse this function later.

##########
File path: cpp/src/arrow/compute/exec/key_hash.cc
##########
@@ -138,6 +138,19 @@ inline uint32_t Hashing::helper_tail(uint32_t offset, 
uint64_t mask, const uint8
   return acc;

Review comment:
       Same here: You can make this method call the other one specifying length 
as `sizeof(uint64_t)`

##########
File path: cpp/src/arrow/compute/exec/key_compare.cc
##########
@@ -276,8 +276,9 @@ void KeyCompare::CompareVarBinaryColumnToRow(
         uint64_t key_right = key_right_ptr[j];
         result_or |= key_left ^ key_right;
       }
-      uint64_t tail_mask = ~0ULL >> (64 - 8 * (length - j * 8));
-      uint64_t key_left = util::SafeLoad(key_left_ptr + j);
+      int32_t tail_length = length - j * 8;
+      uint64_t tail_mask = ~0ULL >> (64 - 8 * (tail_length));

Review comment:
       nit: you probably meant `64 - (8 * tail_length)`? no need for extra 
parens




-- 
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