mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-02 07:11:49 +00:00
Don't crash if write_impl() leaves less buffer space available than expected.
This was tickled by a Clang diagnostic; Clang test case to follow. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@176911 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
46561ce249
commit
b79d25ca9c
@ -306,7 +306,12 @@ raw_ostream &raw_ostream::write(const char *Ptr, size_t Size) {
|
||||
if (LLVM_UNLIKELY(OutBufCur == OutBufStart)) {
|
||||
size_t BytesToWrite = Size - (Size % NumBytes);
|
||||
write_impl(Ptr, BytesToWrite);
|
||||
copy_to_buffer(Ptr + BytesToWrite, Size - BytesToWrite);
|
||||
size_t BytesRemaining = Size - BytesToWrite;
|
||||
if (BytesRemaining > size_t(OutBufEnd - OutBufCur)) {
|
||||
// Too much left over to copy into our buffer.
|
||||
return write(Ptr + BytesToWrite, BytesRemaining);
|
||||
}
|
||||
copy_to_buffer(Ptr + BytesToWrite, BytesRemaining);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user