Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix readVarLong, remove multiplication in readVarInt #853

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ public int readVarInt(ByteBuf buf) {
int size = 0;
int b;
while (((b = buf.readByte()) & 0x80) == 0x80) {
value |= (b & 0x7F) << (size++ * 7);
if (size > 5) {
throw new IllegalArgumentException("VarInt too long (length must be <= 5)");
value |= (b & 0x7F) << size;
size += 7;
if (size > 35) {
throw new IllegalArgumentException("VarInt wider than 35-bit");
}
}

return value | ((b & 0x7F) << (size * 7));
return value | ((b & 0x7F) << size);
}

// Based off of Andrew Steinborn's blog post:
Expand Down Expand Up @@ -127,17 +128,18 @@ private static void writeVarLongFull(ByteBuf buf, long value) {

@Override
public long readVarLong(ByteBuf buf) {
int value = 0;
long value = 0;
int size = 0;
int b;
while (((b = buf.readByte()) & 0x80) == 0x80) {
value |= (b & 0x7F) << (size++ * 7);
if (size > 10) {
throw new IllegalArgumentException("VarLong too long (length must be <= 10)");
value |= (b & 0x7FL) << size;
size += 7;
if (size > 70) {
throw new IllegalArgumentException("VarLong wider than 70-bit");
}
}

return value | ((b & 0x7FL) << (size * 7));
return value | ((b & 0x7FL) << size);
}

@Override
Expand Down
Loading