Skip to content

Commit

Permalink
simpler fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jtattermusch committed Nov 20, 2019
1 parent 71ac3e5 commit 77d3373
Showing 1 changed file with 3 additions and 28 deletions.
31 changes: 3 additions & 28 deletions csharp/src/Google.Protobuf/CodedInputStream.cs
Expand Up @@ -577,32 +577,7 @@ public uint ReadFixed32()
/// </summary>
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;
}

/// <summary>
Expand Down Expand Up @@ -870,7 +845,7 @@ public bool MaybeConsumeTag(uint tag)

internal static bool? ReadBoolWrapper(CodedInputStream input)
{
return ReadUInt32Wrapper(input) != 0;
return ReadUInt64Wrapper(input) != 0;
}

internal static uint? ReadUInt32Wrapper(CodedInputStream input)
Expand Down Expand Up @@ -1679,4 +1654,4 @@ private void SkipImpl(int amountToSkip)
}
#endregion
}
}
}

0 comments on commit 77d3373

Please sign in to comment.