proost commented on code in PR #569:
URL: https://github.com/apache/datasketches-cpp/pull/569#discussion_r4533743827
##########
kll/include/kll_sketch_impl.hpp:
##########
@@ -753,6 +767,21 @@ void kll_sketch<T, C,
A>::add_empty_top_level_to_completely_full_sketch() {
levels_[num_levels_] = new_total_cap; // initialize the new "extra" index at
the top
}
+// Grows the items buffer of a one-level sketch when it is full and smaller
than k.
+// Compaction starts only when the buffer is full at k items, so growing does
not change the result.
+template<typename T, typename C, typename A>
+void kll_sketch<T, C, A>::grow_items() {
Review Comment:
This makes use-after-free problem when using with string and update after
grow_items called.
Consider this case:
```
TEST_CASE("kll sketch: update with aliased item during buffer growth",
"[kll_sketch]") {
const uint16_t k = 5000;
kll_sketch<std::string> sketch(k);
for (int i = 0; i < kll_constants::DEFAULT_K; ++i) {
sketch.update(std::string(64, 'x') + std::to_string(i));
}
REQUIRE(sketch.get_n() == kll_constants::DEFAULT_K);
const std::string& item = sketch.begin()->first;
const std::string expected = item;
// Triggers grow_items()
sketch.update(item);
REQUIRE(sketch.get_n() == kll_constants::DEFAULT_K + 1);
uint32_t count = 0;
for (const auto& entry : sketch) {
if (entry.first == expected) {
++count;
}
}
REQUIRE(count == 2);
}
```
--
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]