From 77d33734cf69cb431c7f82f61141f17765d45f7c Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 20 Nov 2019 12:48:49 +0100 Subject: [PATCH] simpler fix --- .../src/Google.Protobuf/CodedInputStream.cs | 31 ++----------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/csharp/src/Google.Protobuf/CodedInputStream.cs b/csharp/src/Google.Protobuf/CodedInputStream.cs index e405b5b28a..bea6bff34f 100644 --- a/csharp/src/Google.Protobuf/CodedInputStream.cs +++ b/csharp/src/Google.Protobuf/CodedInputStream.cs @@ -577,32 +577,7 @@ namespace Google.Protobuf /// public bool ReadBool() { - int result = 0; // can't do AND on bytes, it gets implicitly upcasted to int - byte index = 0; - if (bufferPos < bufferSize) // check if we have at least one byte for the most likely case of a one byte 1 or 0 - { - result = buffer[bufferPos++]; - if (result < 128) - { - return result != 0; - } - result &= 0x7f; - index++; - } - - do - { - byte b = ReadRawByte(); - result |= b & 0x7F; // OR all bytes together since we don't care about the actual value, just whether is more than zero - if (b < 0x80) - { - return result != 0; - } - index++; - } - while (index < 10); - - throw InvalidProtocolBufferException.MalformedVarint(); + return ReadRawVarint64() != 0; } /// @@ -870,7 +845,7 @@ namespace Google.Protobuf internal static bool? ReadBoolWrapper(CodedInputStream input) { - return ReadUInt32Wrapper(input) != 0; + return ReadUInt64Wrapper(input) != 0; } internal static uint? ReadUInt32Wrapper(CodedInputStream input) @@ -1679,4 +1654,4 @@ namespace Google.Protobuf } #endregion } -} \ No newline at end of file +}