aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Compression.cpp
diff options
context:
space:
mode:
authorCole Kissane <cole.kissane@gmail.com>2022-07-13 15:08:40 -0700
committerCole Kissane <cole.kissane@gmail.com>2022-07-13 15:08:41 -0700
commit6b618a620f0b964f78c176a9dc94bcc35bf0db68 (patch)
tree82cae74deacc18e7d854030457958e21213c3c72 /llvm/lib/Support/Compression.cpp
parentd843d5c8e6c9e16a8ff18cae3ff0aea3c4bace49 (diff)
downloadllvm-6b618a620f0b964f78c176a9dc94bcc35bf0db68.zip
llvm-6b618a620f0b964f78c176a9dc94bcc35bf0db68.tar.gz
llvm-6b618a620f0b964f78c176a9dc94bcc35bf0db68.tar.bz2
[llvm] fix zlib buffer truncate edge cases and fix nits in tests
- add check before truncating (un)compressed data buffer if the buffer is already a perfect length, to avoid triggering truncate assertion in edge case. - explictly coerce LLVM_ENABLE_ZLIB to a 0 or 1 value in OFF case, to match current ON, FORCE_ON behavior. - fix code style nits in zlib tests Reviewed By: phosek Differential Revision: https://reviews.llvm.org/D129698
Diffstat (limited to 'llvm/lib/Support/Compression.cpp')
-rw-r--r--llvm/lib/Support/Compression.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/Support/Compression.cpp b/llvm/lib/Support/Compression.cpp
index 00f88a3..eda67c5 100644
--- a/llvm/lib/Support/Compression.cpp
+++ b/llvm/lib/Support/Compression.cpp
@@ -57,7 +57,8 @@ void zlib::compress(StringRef InputBuffer,
// Tell MemorySanitizer that zlib output buffer is fully initialized.
// This avoids a false report when running LLVM with uninstrumented ZLib.
__msan_unpoison(CompressedBuffer.data(), CompressedSize);
- CompressedBuffer.truncate(CompressedSize);
+ if (CompressedSize < CompressedBuffer.size())
+ CompressedBuffer.truncate(CompressedSize);
}
Error zlib::uncompress(StringRef InputBuffer, char *UncompressedBuffer,
@@ -79,7 +80,8 @@ Error zlib::uncompress(StringRef InputBuffer,
UncompressedBuffer.resize_for_overwrite(UncompressedSize);
Error E = zlib::uncompress(InputBuffer, UncompressedBuffer.data(),
UncompressedSize);
- UncompressedBuffer.truncate(UncompressedSize);
+ if (UncompressedSize < UncompressedBuffer.size())
+ UncompressedBuffer.truncate(UncompressedSize);
return E;
}