leerho commented on code in PR #575:
URL: https://github.com/apache/datasketches-cpp/pull/575#discussion_r4580265209


##########
req/include/req_compactor_impl.hpp:
##########
@@ -211,13 +219,14 @@ void req_compactor<T, C, A>::grow(uint32_t new_capacity) {
     new (new_items + new_i) T(std::move(*it));
     (*it).~T();
   }
-  allocator_.deallocate(items_, capacity_);
+  if (items_ != nullptr) allocator_.deallocate(items_, capacity_);
   items_ = new_items;
   capacity_ = new_capacity;
 }
 
 template<typename T, typename C, typename A>
 void req_compactor<T, C, A>::ensure_space(uint32_t num) {
+  reserve();

Review Comment:
   Good catch, thanks. `ensure_space()` now returns before `reserve()` when 
`num == 0`, so merging an empty compactor leaves an unallocated one 
unallocated. The rest of `merge()` is safe with no storage: with `capacity_` 0, 
`begin()` and `end()` are both null and nothing is copied. The other caller, 
`compact()`, always promotes at least one item.
   
   I added a test, "req compactor allocation: merging an empty compactor 
allocates no item storage", in both HRA and LRA. It fails without the change 
(1152 bytes allocated). `req_test` passes under ASan and UBSan.



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