Use Preconditions.checkPositionIndexes() in ByteBuf.crc32()

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 4 years ago
parent d2ee9d3b8b
commit 5a20b75f4f
  1. 2
      buffer/build.gradle.kts
  2. 5
      buffer/src/main/java/dev/openrs2/buffer/ByteBufExtensions.kt

@ -5,6 +5,8 @@ plugins {
dependencies { dependencies {
api("io.netty:netty-buffer:${Versions.netty}") api("io.netty:netty-buffer:${Versions.netty}")
implementation("com.google.guava:guava:${Versions.guava}")
} }
publishing { publishing {

@ -1,5 +1,6 @@
package dev.openrs2.buffer package dev.openrs2.buffer
import com.google.common.base.Preconditions
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf
import io.netty.buffer.ByteBufUtil import io.netty.buffer.ByteBufUtil
import java.util.zip.CRC32 import java.util.zip.CRC32
@ -85,9 +86,7 @@ public fun ByteBuf.crc32(): Int {
} }
public fun ByteBuf.crc32(index: Int, len: Int): Int { public fun ByteBuf.crc32(index: Int, len: Int): Int {
if (index < 0 || index >= capacity() || len < 0 || (index + len) >= capacity()) { Preconditions.checkPositionIndexes(index, index + len, capacity())
throw IndexOutOfBoundsException()
}
val crc = CRC32() val crc = CRC32()
val count = nioBufferCount() val count = nioBufferCount()

Loading…
Cancel
Save