PR feedback for BinaryReader/Writer buffers
authorIan Hays <ianha@microsoft.com>
Mon, 24 Oct 2016 20:26:42 +0000 (13:26 -0700)
committerIan Hays <ianha@microsoft.com>
Mon, 24 Oct 2016 20:26:42 +0000 (13:26 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/e807e3de05ef0434fec600f3cda8ca8461d3b947

src/coreclr/src/mscorlib/src/System/IO/BinaryReader.cs
src/coreclr/src/mscorlib/src/System/IO/BinaryWriter.cs

index 32e26c0..8accf0b 100644 (file)
@@ -375,22 +375,20 @@ namespace System.IO {
 
                 checked
                 {
-                    if (position < 0 || numBytes < 0 || position + numBytes > byteBuffer.Length)
+                    if (position < 0 || numBytes < 0 || position > byteBuffer.Length - numBytes)
                     {
-                        throw new ArgumentOutOfRangeException(nameof(byteCount));
+                        throw new ArgumentOutOfRangeException(nameof(numBytes));
                     }
-                    if (index < 0 || charsRemaining < 0 || index + charsRemaining > buffer.Length)
+                    if (index < 0 || charsRemaining < 0 || index > buffer.Length - charsRemaining)
                     {
                         throw new ArgumentOutOfRangeException(nameof(charsRemaining));
                     }
                     unsafe
                     {
                         fixed (byte* pBytes = byteBuffer)
+                        fixed (char* pChars = buffer)
                         {
-                            fixed (char* pChars = buffer)
-                            {
-                                charsRead = m_decoder.GetChars(pBytes + position, numBytes, pChars + index, charsRemaining, false);
-                            }
+                            charsRead = m_decoder.GetChars(pBytes + position, numBytes, pChars + index, charsRemaining, flush: false);
                         }
                     }
                 }
index 03fe51f..c775cbc 100644 (file)
@@ -194,7 +194,7 @@ namespace System.IO {
             Contract.Assert(_encoding.GetMaxByteCount(1) <= 16, "_encoding.GetMaxByteCount(1) <= 16)");
             int numBytes = 0;
             fixed(byte * pBytes = _buffer) {
-                numBytes = _encoder.GetBytes(&ch, 1, pBytes, _buffer.Length, true);
+                numBytes = _encoder.GetBytes(&ch, 1, pBytes, _buffer.Length, flush: true);
             }
             OutStream.Write(_buffer, 0, numBytes);
         }
@@ -387,7 +387,7 @@ namespace System.IO {
 
                     checked
                     {
-                        if (charStart < 0 || charCount < 0 || charStart + charCount > value.Length)
+                        if (charStart < 0 || charCount < 0 || charStart > value.Length - charCount)
                         {
                             throw new ArgumentOutOfRangeException(nameof(charCount));
                         }