diff --git a/lucene/src/java/org/apache/lucene/index/codecs/MultiLevelSkipListReader.java b/lucene/src/java/org/apache/lucene/index/codecs/MultiLevelSkipListReader.java index a883c25e2f4..bef7f11414a 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/MultiLevelSkipListReader.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/MultiLevelSkipListReader.java @@ -186,9 +186,11 @@ public abstract class MultiLevelSkipListReader { /** returns x == 0 ? 0 : Math.floor(Math.log(x) / Math.log(base)) */ static int log(int x, int base) { + assert base >= 2; int ret = 0; - while (x >= base) { - x /= base; + long n = base; // needs to be a long to avoid overflow + while (x >= n) { + n *= base; ret++; } return ret;