diff --git a/llvm/lib/Support/BinaryStreamWriter.cpp b/llvm/lib/Support/BinaryStreamWriter.cpp --- a/llvm/lib/Support/BinaryStreamWriter.cpp +++ b/llvm/lib/Support/BinaryStreamWriter.cpp @@ -13,6 +13,8 @@ #include "llvm/Support/BinaryStreamRef.h" #include "llvm/Support/LEB128.h" +#include + using namespace llvm; BinaryStreamWriter::BinaryStreamWriter(WritableBinaryStreamRef Ref) @@ -94,10 +96,12 @@ Error BinaryStreamWriter::padToAlignment(uint32_t Align) { uint64_t NewOffset = alignTo(Offset, Align); - if (NewOffset > getLength()) - return make_error(stream_error_code::stream_too_short); + const uint64_t ZerosSize = 64; + char Zeros[ZerosSize]; + std::memset(Zeros, 0, ZerosSize); while (Offset < NewOffset) - if (auto EC = writeInteger('\0')) - return EC; + if (auto E = writeArray( + ArrayRef(Zeros, std::min(ZerosSize, NewOffset - Offset)))) + return E; return Error::success(); }