Tell MSan that memory initialized by libz is valid
authorAlexey Samsonov <samsonov@google.com>
Tue, 23 Apr 2013 12:17:46 +0000 (12:17 +0000)
committerAlexey Samsonov <samsonov@google.com>
Tue, 23 Apr 2013 12:17:46 +0000 (12:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180094 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/Compression.cpp

index f22d3db9ac94423bd4f99961813e4dad52edd05f..36afa8c06b14287b724af4d540c20b1c132374e9 100644 (file)
@@ -15,6 +15,7 @@
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Config/config.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MemoryBuffer.h"
 #if LLVM_ENABLE_ZLIB == 1 && HAVE_ZLIB_H
@@ -55,9 +56,12 @@ zlib::Status zlib::compress(StringRef InputBuffer,
   Status Res = encodeZlibReturnValue(::compress2(
       (Bytef *)TmpBuffer.get(), &CompressedSize,
       (const Bytef *)InputBuffer.data(), InputBuffer.size(), CLevel));
-  if (Res == StatusOK)
+  if (Res == StatusOK) {
     CompressedBuffer.reset(MemoryBuffer::getMemBufferCopy(
         StringRef(TmpBuffer.get(), CompressedSize)));
+    // Tell MSan that memory initialized by zlib is valid.
+    __msan_unpoison(CompressedBuffer.data(), CompressedBuffer.size());
+  }
   return Res;
 }
 
@@ -68,9 +72,12 @@ zlib::Status zlib::uncompress(StringRef InputBuffer,
   Status Res = encodeZlibReturnValue(
       ::uncompress((Bytef *)TmpBuffer.get(), (uLongf *)&UncompressedSize,
                    (const Bytef *)InputBuffer.data(), InputBuffer.size()));
-  if (Res == StatusOK)
+  if (Res == StatusOK) {
     UncompressedBuffer.reset(MemoryBuffer::getMemBufferCopy(
         StringRef(TmpBuffer.get(), UncompressedSize)));
+    // Tell MSan that memory initialized by zlib is valid.
+    __msan_unpoison(UncompressedBuffer.data(), UncompressedBuffer.size());
+  }
   return Res;
 }