Writing 4k of zeros is preferrable to 4k of random memory. Document that. While
there remove the initialization of the first byte of the buffer and start at
index zero. It was writing a literal '0' instead of a null byte at the
beginning anyways, which didn't matter since we never read it.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234202
91177308-0d34-0410-b5e6-
96231b3b80d8
if (RequestLen < ScratchBufSize)
RequestLen = ScratchBufSize;
+ // Get scratch buffer. Zero-initialize it so it can be dumped into a PCH file
+ // deterministically.
std::unique_ptr<llvm::MemoryBuffer> OwnBuf =
- llvm::MemoryBuffer::getNewUninitMemBuffer(RequestLen, "<scratch space>");
+ llvm::MemoryBuffer::getNewMemBuffer(RequestLen, "<scratch space>");
llvm::MemoryBuffer &Buf = *OwnBuf;
FileID FID = SourceMgr.createFileID(std::move(OwnBuf));
BufferStartLoc = SourceMgr.getLocForStartOfFile(FID);
CurBuffer = const_cast<char*>(Buf.getBufferStart());
- BytesUsed = 1;
- CurBuffer[0] = '0'; // Start out with a \0 for cleanliness.
+ BytesUsed = 0;
}