Rich-T-kid commented on code in PR #12149:
URL: https://github.com/apache/arrow-rs/pull/12149#discussion_r4571039012


##########
arrow-buffer/src/buffer/offset.rs:
##########
@@ -208,11 +208,22 @@ impl<O: ArrowNativeType> OffsetBuffer<O> {
         O::from_usize(total_length)
             .ok_or_else(|| 
OverflowError::new::<O>("offset").with_value(total_length))?;
 
-        let offsets = (0..=n)
-            .map(|index| O::usize_as(index * length))
-            .collect::<Vec<O>>();
+        let len_bytes = n
+            .checked_add(1)
+            .and_then(|o| o.checked_mul(std::mem::size_of::<O>()))
+            .ok_or_else(|| OverflowError::new::<usize>("buffer length"))?;
+
+        let mut buffer = MutableBuffer::try_with_capacity(len_bytes)

Review Comment:
   Could we update the `# Errors` docs here and on 
`GenericByteArray::try_new_repeated` to mention allocation failures? Both can 
now return an error when the offset buffer cannot be allocated, but the current 
docs only mention arithmetic and offset overflow.



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