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

Signed-off-by: Graham <gpe@openrs2.dev>
pull/132/head
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 {
api("io.netty:netty-buffer:${Versions.netty}")
implementation("com.google.guava:guava:${Versions.guava}")
}
publishing {

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

Loading…
Cancel
Save