File tree 2 files changed +38
-1
lines changed
core/kotlinx-coroutines-io/src
main/kotlin/kotlinx/coroutines/experimental/io
test/kotlin/kotlinx/coroutines/experimental/io
2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -811,8 +811,10 @@ internal class ByteBufferChannel(
811
811
}
812
812
813
813
private fun ByteBuffer.rollBytes (n : Int ) {
814
+ val rem = remaining()
815
+
814
816
limit(position() + n)
815
- for (i in 1 .. n - remaining() ) {
817
+ for (i in 0 until n - rem ) {
816
818
put(capacity() + ReservedLongIndex + i, get(i))
817
819
}
818
820
}
Original file line number Diff line number Diff line change @@ -185,6 +185,41 @@ class ByteBufferChannelTest : TestBase() {
185
185
}
186
186
}
187
187
188
+ @Test
189
+ fun testIntEdge2 () {
190
+ runTest {
191
+ for (shift in 1 .. 3 ) {
192
+ for (i in 1 .. shift) {
193
+ ch.writeByte(1 )
194
+ }
195
+
196
+ repeat(Size / 4 - 1 ) {
197
+ ch.writeInt(0xeeeeeeeeL )
198
+ }
199
+
200
+ ch.flush()
201
+
202
+ for (i in 1 .. shift) {
203
+ ch.readByte()
204
+ }
205
+
206
+ ch.writeByte(0x12 )
207
+ ch.writeByte(0x34 )
208
+ ch.writeByte(0x56 )
209
+ ch.writeByte(0x78 )
210
+
211
+ ch.flush()
212
+
213
+ while (ch.availableForRead > 4 ) {
214
+ ch.readInt()
215
+ }
216
+
217
+ assertEquals(0x12345678 , ch.readInt())
218
+ }
219
+ }
220
+ }
221
+
222
+
188
223
@Test
189
224
fun testLongB () {
190
225
runTest {
You can’t perform that action at this time.
0 commit comments