summaryrefslogtreecommitdiff
path: root/lib/Support/raw_ostream.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2011-08-28 03:30:02 +0000
committerNick Lewycky <nicholas@mxc.ca>2011-08-28 03:30:02 +0000
commitb1b051ec97c4e3c02cea554e169cbb4f85bcb2de (patch)
tree2f97376387254854e46e0aa6dd60021973ff6056 /lib/Support/raw_ostream.cpp
parentf5ec9b55e871d326b8917f203711529273e7fa54 (diff)
downloadllvm-b1b051ec97c4e3c02cea554e169cbb4f85bcb2de.tar.gz
llvm-b1b051ec97c4e3c02cea554e169cbb4f85bcb2de.tar.bz2
llvm-b1b051ec97c4e3c02cea554e169cbb4f85bcb2de.tar.xz
Fix integer overflow bug in raw_ostream::write. This showed up as a
non-deterministic crash in the test suite. Fixes PR10055! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138717 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/raw_ostream.cpp')
-rw-r--r--lib/Support/raw_ostream.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
index 5a71fa3d8c..c9cf249500 100644
--- a/lib/Support/raw_ostream.cpp
+++ b/lib/Support/raw_ostream.cpp
@@ -84,7 +84,7 @@ void raw_ostream::SetBuffered() {
}
void raw_ostream::SetBufferAndMode(char *BufferStart, size_t Size,
- BufferKind Mode) {
+ BufferKind Mode) {
assert(((Mode == Unbuffered && BufferStart == 0 && Size == 0) ||
(Mode != Unbuffered && BufferStart && Size)) &&
"stream must be unbuffered or have at least one byte");
@@ -284,7 +284,7 @@ raw_ostream &raw_ostream::write(unsigned char C) {
raw_ostream &raw_ostream::write(const char *Ptr, size_t Size) {
// Group exceptional cases into a single branch.
- if (BUILTIN_EXPECT(OutBufCur+Size > OutBufEnd, false)) {
+ if (BUILTIN_EXPECT(size_t(OutBufEnd - OutBufCur) < Size, false)) {
if (BUILTIN_EXPECT(!OutBufStart, false)) {
if (BufferMode == Unbuffered) {
write_impl(Ptr, Size);