From a223ef3c4fa01da1deb8a453e3aa9c9021bcc939 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Mon, 24 May 2021 05:12:49 -0600 Subject: [PATCH] Tests: Use ByteBuffer::create_zeroed in TestDeflate instead of memset The round trip compress test wants the first half of the byte buffer to be filled with random data, and the second half to be all zeroes. The strategy of using memset on ByteBuffer::offset_pointer confuses __builtin_memset_chk when building with -fsanitize=undefined. It thinks that the buffer is using inline capacity when we can prove to ourselves pretty easily that it's not. To avoid this, just create the buffer zeroed to start, and then fill the first half with the random data. --- Tests/LibCompress/TestDeflate.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Tests/LibCompress/TestDeflate.cpp b/Tests/LibCompress/TestDeflate.cpp index 7b992d8fee..138d75ec80 100644 --- a/Tests/LibCompress/TestDeflate.cpp +++ b/Tests/LibCompress/TestDeflate.cpp @@ -124,9 +124,8 @@ TEST_CASE(deflate_round_trip_store) TEST_CASE(deflate_round_trip_compress) { - auto original = ByteBuffer::create_uninitialized(2048); - fill_with_random(original.data(), 1024); - memset(original.offset_pointer(1024), 0, 1024); // we fill the second half with 0s to make sure we test back references as well + auto original = ByteBuffer::create_zeroed(2048); + fill_with_random(original.data(), 1024); // we pre-filled the second half with 0s to make sure we test back references as well // Since the different levels just change how much time is spent looking for better matches, just use fast here to reduce test time auto compressed = Compress::DeflateCompressor::compress_all(original, Compress::DeflateCompressor::CompressionLevel::FAST); EXPECT(compressed.has_value());