wiedld commented on code in PR #13802:
URL: https://github.com/apache/datafusion/pull/13802#discussion_r1888729596


##########
datafusion/functions/src/strings.rs:
##########
@@ -124,8 +125,18 @@ pub struct StringArrayBuilder {
 
 impl StringArrayBuilder {
     pub fn with_capacity(item_capacity: usize, data_capacity: usize) -> Self {
-        let mut offsets_buffer =
-            MutableBuffer::with_capacity((item_capacity + 1) * 
size_of::<i32>());
+        // MutableBuffer::with_capacity will round up to multiples of 
`ALIGNMENT`
+        let capacity = std::cmp::max(
+            item_capacity.saturating_add(1).saturating_mul(ALIGNMENT),
+            data_capacity,
+        );
+        // rust core's Layout::from_size_align is capped at isize::Max
+        let capacity = std::cmp::min(

Review Comment:
   I suppose it doesn't matter where it panics, as long as we get the proper 
panic. I fixed based on the [approach you mentioned 
here](https://github.com/apache/datafusion/pull/13802#discussion_r1888360133).



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to