From 3731604f1f73cb29a9554660b27aecba1c5c032b Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 18 Aug 2009 20:09:59 +0000 Subject: Fix a bug in raw_ostream::write(char) introduced by the change to allow underlying stream classes to decline buffering. After calling SetBuffered(), re-check whether the stream is Unbuffered in order to handle the case where the underlying stream has declined buffering. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79362 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/raw_ostream.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'lib/Support/raw_ostream.cpp') diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp index a91fe9b..0c1843c 100644 --- a/lib/Support/raw_ostream.cpp +++ b/lib/Support/raw_ostream.cpp @@ -187,10 +187,17 @@ raw_ostream &raw_ostream::write(unsigned char C) { return *this; } - if (!OutBufStart) - SetBuffered(); - else + if (OutBufStart) flush_nonempty(); + else { + SetBuffered(); + // It's possible for the underlying stream to decline + // buffering, so check this condition again. + if (Unbuffered) { + write_impl(reinterpret_cast(&C), 1); + return *this; + } + } } *OutBufCur++ = C; -- cgit v1.1