diff --git a/sampling/include/ebpps_sketch_impl.hpp b/sampling/include/ebpps_sketch_impl.hpp index 9a7b23e3..574a6917 100644 --- a/sampling/include/ebpps_sketch_impl.hpp +++ b/sampling/include/ebpps_sketch_impl.hpp @@ -331,7 +331,7 @@ auto ebpps_sketch::serialize(unsigned header_size_bytes, const SerDe& sd) c const size_t size = header_size_bytes + (prelongs << 3) + sample_.get_serialized_size_bytes(sd); vector_bytes bytes(size, 0, allocator_); uint8_t* ptr = bytes.data() + header_size_bytes; - const uint8_t* end_ptr = ptr + size; + const uint8_t* end_ptr = bytes.data() + size; uint8_t flags = 0; if (is_empty()) { diff --git a/sampling/test/ebpps_sketch_test.cpp b/sampling/test/ebpps_sketch_test.cpp index 5ee72813..e104e319 100644 --- a/sampling/test/ebpps_sketch_test.cpp +++ b/sampling/test/ebpps_sketch_test.cpp @@ -301,4 +301,15 @@ TEST_CASE("ebpps sketch: merge keeps the max weight", "[ebpps_sketch]") { REQUIRE(sk4.get_c() == Approx(ref.get_c()).margin(EPS)); } -} \ No newline at end of file +TEST_CASE("ebpps sketch: serialize with header", "[ebpps_sketch]") { + auto sk = create_unweighted_sketch(10, 25); + const size_t body_size = sk.get_serialized_size_bytes(); + for (unsigned header_size : {0u, 1u, 8u, 13u}) { + auto bytes = sk.serialize(header_size); + REQUIRE(bytes.size() == header_size + body_size); + auto sk2 = ebpps_sketch::deserialize(bytes.data() + header_size, bytes.size() - header_size); + check_if_equal(sk, sk2); + } +} + +}