projects
/
oota-llvm.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
46561ce
)
Don't crash if write_impl() leaves less buffer space available than expected.
author
Matt Beaumont-Gay
<matthewbg@google.com>
Tue, 12 Mar 2013 23:55:24 +0000
(23:55 +0000)
committer
Matt Beaumont-Gay
<matthewbg@google.com>
Tue, 12 Mar 2013 23:55:24 +0000
(23:55 +0000)
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
lib/Support/raw_ostream.cpp
patch
|
blob
|
history
diff --git
a/lib/Support/raw_ostream.cpp
b/lib/Support/raw_ostream.cpp
index f71abd3b2443ae15fef2768946621fd2a6bd1601..da26a371a76286749280416dfe397e3228118060 100644
(file)
--- a/
lib/Support/raw_ostream.cpp
+++ b/
lib/Support/raw_ostream.cpp
@@
-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;
}