Skip to content

Commit 7b1b563

Browse files
author
Sergey Mashkov
committed
Add IoBuffer preconditions
1 parent aa14b9b commit 7b1b563

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

kotlinx-io-js/src/main/kotlin/kotlinx/io/core/IoBufferJS.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ actual class IoBuffer internal constructor(
2727
private var littleEndian = false
2828
private var platformEndian = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN
2929

30+
init {
31+
require(origin !== this) { "origin shouldn't point to itself" }
32+
}
33+
3034
@ExperimentalIoApi
3135
actual var attachment: Any? = null
3236

kotlinx-io-jvm/src/main/kotlin/kotlinx/io/core/IoBufferJVM.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ actual class IoBuffer private constructor(
4646
}
4747

4848
init {
49+
require(origin !== this) { "origin shouldn't point to itself" }
4950
readBuffer.limit(0)
5051
}
5152

kotlinx-io-native/src/main/kotlin/kotlinx/io/core/IoBufferNative.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ actual class IoBuffer internal constructor(
3838

3939
override val endOfInput: Boolean get() = !canRead()
4040

41+
init {
42+
require(contentCapacity >= 0) { "contentCapacity shouln't be negative: $contentCapacity" }
43+
require(this !== origin) { "origin shouldn't point to itself" }
44+
}
45+
4146
actual final override var byteOrder: ByteOrder = ByteOrder.BIG_ENDIAN
4247
set(newOrder) {
4348
field = newOrder

0 commit comments

Comments
 (0)