aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-08-23 20:31:39 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-08-23 20:31:39 +0000
commitffbbf314f1740b9d73c5af1ad1aa3e731dac026b (patch)
treece52791943346ccf557a8aa28979b3f157d58f4e /lib
parent165b4dfeba7c1b0e7d3ca0ef71c276f585fee79f (diff)
downloadexternal_llvm-ffbbf314f1740b9d73c5af1ad1aa3e731dac026b.zip
external_llvm-ffbbf314f1740b9d73c5af1ad1aa3e731dac026b.tar.gz
external_llvm-ffbbf314f1740b9d73c5af1ad1aa3e731dac026b.tar.bz2
Fix off-by-one in llvm::Format::print.
- This also shortens the Format.h implementation, and uses the print buffer fully (it was wasting a character). - This manifested as llvm-test failures, because one side effect was that raw_ostream would write garbage '\x00' values into the output stream if it happened that the string was at the end of the buffer. This meant that grep would report 'Binary file matches', which meant the silly pattern matching llvm-test eventually does would fail. Cute. :) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79862 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Support/raw_ostream.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
index 2181cce..221859d 100644
--- a/lib/Support/raw_ostream.cpp
+++ b/lib/Support/raw_ostream.cpp
@@ -253,12 +253,12 @@ raw_ostream &raw_ostream::operator<<(const format_object_base &Fmt) {
// If we have more than a few bytes left in our output buffer, try
// formatting directly onto its end.
size_t NextBufferSize = 127;
- if (OutBufEnd-OutBufCur > 3) {
- size_t BufferBytesLeft = OutBufEnd-OutBufCur;
+ size_t BufferBytesLeft = OutBufEnd - OutBufCur;
+ if (BufferBytesLeft > 3) {
size_t BytesUsed = Fmt.print(OutBufCur, BufferBytesLeft);
// Common case is that we have plenty of space.
- if (BytesUsed < BufferBytesLeft) {
+ if (BytesUsed <= BufferBytesLeft) {
OutBufCur += BytesUsed;
return *this;
}
@@ -277,11 +277,11 @@ raw_ostream &raw_ostream::operator<<(const format_object_base &Fmt) {
V.resize(NextBufferSize);
// Try formatting into the SmallVector.
- size_t BytesUsed = Fmt.print(&V[0], NextBufferSize);
+ size_t BytesUsed = Fmt.print(V.data(), NextBufferSize);
// If BytesUsed fit into the vector, we win.
if (BytesUsed <= NextBufferSize)
- return write(&V[0], BytesUsed);
+ return write(V.data(), BytesUsed);
// Otherwise, try again with a new size.
assert(BytesUsed > NextBufferSize && "Didn't grow buffer!?");