metsw24-max commented on code in PR #49883:
URL: https://github.com/apache/arrow/pull/49883#discussion_r3541852155


##########
cpp/src/arrow/buffer_builder.h:
##########
@@ -91,11 +102,25 @@ class ARROW_EXPORT BufferBuilder {
   /// \param[in] additional_bytes number of additional bytes to make space for
   /// \return Status
   Status Reserve(const int64_t additional_bytes) {
-    auto min_capacity = size_ + additional_bytes;
+    if (ARROW_PREDICT_FALSE(additional_bytes < 0)) {

Review Comment:
   Sorry, missed replying here earlier. The negative/too-large capacity checks 
are centralised in `ValidateBufferCapacity` in memory_pool.cc, so anything 
going through `PoolBuffer::Reserve`/`Resize` is covered. The other repetition 
was the element-to-byte conversions in `TypedBufferBuilder`, which I've now 
folded into a single `ElementsToBytes` helper. The two add-overflow checks left 
in `BufferBuilder::Reserve`/`Append` need the intermediate sum for the capacity 
logic, so factoring those out didn't seem worth it.



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