diff --git a/src/Formats/MarkInCompressedFile.cpp b/src/Formats/MarkInCompressedFile.cpp index fd17525d793..f305fbfa0ac 100644 --- a/src/Formats/MarkInCompressedFile.cpp +++ b/src/Formats/MarkInCompressedFile.cpp @@ -63,7 +63,7 @@ MarksInCompressedFile::MarksInCompressedFile(const PlainArray & marks) // Overallocate by +1 element to let the bit packing/unpacking do less bounds checking. size_t packed_length = (packed_bits + 63) / 64 + 1; - packed.reserve(packed_length); + packed.reserve_exact(packed_length); packed.resize_fill(packed_length); // Second pass: write out the packed marks. diff --git a/src/Formats/tests/gtest_marks.cpp b/src/Formats/tests/gtest_marks.cpp index 334e99d2ec6..47ec0eea46c 100644 --- a/src/Formats/tests/gtest_marks.cpp +++ b/src/Formats/tests/gtest_marks.cpp @@ -35,18 +35,29 @@ TEST(Marks, Compression) EXPECT_LE((marks.approximateMemoryUsage() - sizeof(MarksInCompressedFile)) * 8, plain.size() * max_bits_per_mark); }; - // Typical. - test(gen(10000, 1'000'000, 0), 30); + { + SCOPED_TRACE("Typical"); + test(gen(10000, 1'000'000, 0), 30); + } - // Completely random 64-bit values. - test(gen(10000, UINT64_MAX - 1, UINT64_MAX - 1), 130); - // All zeros. - test(gen(10000, 0, 0), 2); + { + SCOPED_TRACE("Completely random 64-bit values"); + test(gen(10000, UINT64_MAX - 1, UINT64_MAX - 1), 130); + } - // Short. - test(gen(10, 1000, 1000), 65); + { + SCOPED_TRACE("All zeros"); + test(gen(10000, 0, 0), 2); + } - // Empty. - test(gen(0, 0, 0), 0); + { + SCOPED_TRACE("Short"); + test(gen(10, 1000, 1000), 65); + } + + { + SCOPED_TRACE("Empty"); + test(gen(0, 0, 0), 0); + } }