From 4bb47cafcd89735bb0e6c76587f712cfaafe45db Mon Sep 17 00:00:00 2001 From: "ager@google.com" Date: Wed, 8 Feb 2012 10:51:58 +0000 Subject: [PATCH] Fix problem with socket input stream on MacOS when reading from tty. This could cause an empty buffer to be added to an internal BufferList which violates our assumptions. R=sgjesse@google.com BUG= TEST= Review URL: https://chromiumcodereview.appspot.com//9348050 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4027 260f80e4-7a28-3924-810f-c04153c831b5 --- runtime/bin/socket_stream_impl.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/runtime/bin/socket_stream_impl.dart b/runtime/bin/socket_stream_impl.dart index 495104f4c61..d04c41bfb43 100644 --- a/runtime/bin/socket_stream_impl.dart +++ b/runtime/bin/socket_stream_impl.dart @@ -19,7 +19,13 @@ class _SocketInputStream implements SocketInputStream { } ByteArray buffer = new ByteArray(bytesToRead); int bytesRead = _socket.readList(buffer, 0, bytesToRead); - if (bytesRead < bytesToRead) { + if (bytesRead == 0) { + // On MacOS when reading from a tty Ctrl-D will result in one + // byte reported as available. Attempting to read it out will + // result in zero bytes read. When that happens there is no data + // which is indicated by a null return value. + return null; + } else if (bytesRead < bytesToRead) { ByteArray newBuffer = new ByteArray(bytesRead); newBuffer.setRange(0, bytesRead, buffer); return newBuffer;