]> granicus.if.org Git - llvm/commitdiff
Fix a bug in raw_ostream::write(char) introduced by the change to
authorDan Gohman <gohman@apple.com>
Tue, 18 Aug 2009 20:09:59 +0000 (20:09 +0000)
committerDan Gohman <gohman@apple.com>
Tue, 18 Aug 2009 20:09:59 +0000 (20:09 +0000)
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

index a91fe9b5364cb4d35b1a71f78ddcf8e8bf8b9395..0c1843c457c0f4d47e3189b6b0e3f187517cc2fe 100644 (file)
@@ -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<char*>(&C), 1);
+        return *this;
+      }
+    }
   }
 
   *OutBufCur++ = C;