Ferry Huberts <ferry.huberts@xxxxxxxxxx> wrote: > Shawn O. Pearce wrote: > > A 64 bit JVM might actually be able to dedicate more than 2 GiB of Please don't quote everything if you are only replying to a tiny part. > > private static int tableSize(final WindowCacheConfig cfg) { > > final int wsz = cfg.getPackedGitWindowSize(); > > - final int limit = cfg.getPackedGitLimit(); > > + final long limit = cfg.getPackedGitLimit(); > > if (wsz <= 0) > > throw new IllegalArgumentException("Invalid window size"); > > if (limit < wsz) > > throw new IllegalArgumentException("Window size must be < limit"); > > - return 5 * (limit / wsz) / 2; > > + return (int) Math.min(5 * (limit / wsz) / 2, 2000000000); > > Math.min returns a long because the prototype Math.min(long,long) will > be chosen. The cast can then overflow and fail. Better change the return > type to a long: > + return Math.min(5 * (limit / wsz) / 2, 2000000000L); If you looked at that, 2,000,000,000 is within the range of an int. We select the smallest value. The first argument expression is computed as a long, so we shouldn't ever overflow and cause the first argument to be negative. If the first argument is larger than 2 billion, then it does risk overflow, but the 2nd argument is smaller, so it is returned. The code is fine as is. -- Shawn. -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html