Jan Tattermusch 5 лет назад
Родитель
Сommit
9ca0877db1
1 измененных файлов с 3 добавлено и 3 удалено
  1. 3 3
      csharp/src/Google.Protobuf/WritingPrimitives.cs

+ 3 - 3
csharp/src/Google.Protobuf/WritingPrimitives.cs

@@ -428,7 +428,7 @@ namespace Google.Protobuf
         /// </summary>
         /// </summary>
         public static void WriteRawBytes(ref Span<byte> buffer, ref WriterInternalState state, ReadOnlySpan<byte> value)
         public static void WriteRawBytes(ref Span<byte> buffer, ref WriterInternalState state, ReadOnlySpan<byte> value)
         {
         {
-            if (state.limit - state.position >= value.Length)
+            if (buffer.Length - state.position >= value.Length)
             {
             {
                 // We have room in the current buffer.    
                 // We have room in the current buffer.    
                 value.CopyTo(buffer.Slice(state.position, value.Length));
                 value.CopyTo(buffer.Slice(state.position, value.Length));
@@ -443,9 +443,9 @@ namespace Google.Protobuf
                 // Current this is not being done to avoid specialcasing the code for
                 // Current this is not being done to avoid specialcasing the code for
                 // CodedOutputStream vs IBufferWriter<byte>.
                 // CodedOutputStream vs IBufferWriter<byte>.
                 int bytesWritten = 0;
                 int bytesWritten = 0;
-                while (state.limit - state.position < value.Length - bytesWritten)
+                while (buffer.Length - state.position < value.Length - bytesWritten)
                 {
                 {
-                    int length = state.limit - state.position;
+                    int length = buffer.Length - state.position;
                     value.Slice(bytesWritten, length).CopyTo(buffer.Slice(state.position, length));
                     value.Slice(bytesWritten, length).CopyTo(buffer.Slice(state.position, length));
                     bytesWritten += length;
                     bytesWritten += length;
                     state.position += length;
                     state.position += length;