From ebad3d1005bfba1dc0e9262ddd1fb79a095a03c9 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 25 May 2020 16:05:36 -0400 Subject: [PATCH] Use Integer.MIN_VALUE for the sentinel for readVarIntSafely() --- .../com/velocitypowered/proxy/protocol/ProtocolUtils.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java index a112c9681..5c602014f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java @@ -28,7 +28,7 @@ public enum ProtocolUtils { */ public static int readVarInt(ByteBuf buf) { int read = readVarIntSafely(buf); - if (read == -1) { + if (read == Integer.MIN_VALUE) { throw MinecraftDecoder.DEBUG ? BAD_VARINT_CACHED : new CorruptedFrameException("Bad varint decoded"); } @@ -40,19 +40,19 @@ public enum ProtocolUtils { * method and {@link #readVarInt(ByteBuf)} is that this function returns a sentinel value if the * varint is invalid. * @param buf the buffer to read from - * @return the decoded VarInt, or {@code -1} if the varint is invalid + * @return the decoded VarInt, or {@code Integer.MIN_VALUE} if the varint is invalid */ public static int readVarIntSafely(ByteBuf buf) { int i = 0; int j = 0; while (true) { if (!buf.isReadable()) { - return -1; + return Integer.MIN_VALUE; } int k = buf.readByte(); i |= (k & 0x7F) << j++ * 7; if (j > 5) { - return -1; + return Integer.MIN_VALUE; } if ((k & 0x80) != 128) { break;