From 97ebbb1dbbde0be1b4c04ce5cae463f4ed30166c Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Sun, 9 Aug 2020 12:51:02 -0700 Subject: [PATCH] Additional assertion to validate invariants --- core/src/com/riiablo/io/BitInput.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/com/riiablo/io/BitInput.java b/core/src/com/riiablo/io/BitInput.java index cd877476..e5efda11 100644 --- a/core/src/com/riiablo/io/BitInput.java +++ b/core/src/com/riiablo/io/BitInput.java @@ -234,6 +234,7 @@ public class BitInput { private long readCacheSafe(int bits) { assert bits > 0 : "bits(" + bits + ") < " + 1; assert bits < Long.SIZE : "bits(" + bits + ") > " + (Long.SIZE - 1); + assert bitsCached < bits : "bitsCached(" + bitsCached + ") >= bits(" + bits + ")"; final int bitsToAddCount = bits - bitsCached; final int overflowBits = Byte.SIZE - bitsToAddCount; final long nextByte = byteInput._read8u(); @@ -254,6 +255,7 @@ public class BitInput { private long readCacheUnsafe(int bits) { assert bits > 0 : "bits(" + bits + ") < " + 1; assert bits < Long.SIZE : "bits(" + bits + ") > " + (Long.SIZE - 1); + assert bitsCached >= bits : "bitsCached(" + bitsCached + ") < bits(" + bits + ")"; final long bitsOut = cache & MASKS[bits]; cache >>>= bits; bitsCached -= bits;