This commit is contained in:
parent
6cd9045b96
commit
77b4ec7e1b
@ -233,8 +233,8 @@ abstract class PoolArena<T> {
|
||||
allocate(parent.threadCache.get(), buf, newCapacity);
|
||||
if (newCapacity > oldCapacity) {
|
||||
memoryCopy(
|
||||
oldMemory, oldOffset + readerIndex,
|
||||
buf.memory, buf.offset + readerIndex, writerIndex - readerIndex);
|
||||
oldMemory, oldOffset,
|
||||
buf.memory, buf.offset, oldCapacity);
|
||||
} else if (newCapacity < oldCapacity) {
|
||||
if (readerIndex < newCapacity) {
|
||||
if (writerIndex > newCapacity) {
|
||||
|
@ -141,8 +141,8 @@ public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf {
|
||||
if (newCapacity > oldCapacity) {
|
||||
ByteBuffer oldBuffer = buffer;
|
||||
ByteBuffer newBuffer = ByteBuffer.allocateDirect(newCapacity);
|
||||
oldBuffer.position(readerIndex).limit(writerIndex);
|
||||
newBuffer.position(readerIndex).limit(writerIndex);
|
||||
oldBuffer.position(0).limit(oldBuffer.capacity());
|
||||
newBuffer.position(0).limit(oldBuffer.capacity());
|
||||
newBuffer.put(oldBuffer);
|
||||
newBuffer.clear();
|
||||
setByteBuffer(newBuffer);
|
||||
|
@ -112,7 +112,7 @@ public class UnpooledHeapByteBuf extends AbstractReferenceCountedByteBuf {
|
||||
int oldCapacity = array.length;
|
||||
if (newCapacity > oldCapacity) {
|
||||
byte[] newArray = new byte[newCapacity];
|
||||
System.arraycopy(array, readerIndex(), newArray, readerIndex(), readableBytes());
|
||||
System.arraycopy(array, 0, newArray, 0, array.length);
|
||||
setArray(newArray);
|
||||
} else if (newCapacity < oldCapacity) {
|
||||
byte[] newArray = new byte[newCapacity];
|
||||
|
@ -145,8 +145,8 @@ public class UnpooledUnsafeDirectByteBuf extends AbstractReferenceCountedByteBuf
|
||||
if (newCapacity > oldCapacity) {
|
||||
ByteBuffer oldBuffer = buffer;
|
||||
ByteBuffer newBuffer = ByteBuffer.allocateDirect(newCapacity);
|
||||
oldBuffer.position(readerIndex).limit(writerIndex);
|
||||
newBuffer.position(readerIndex).limit(writerIndex);
|
||||
oldBuffer.position(0).limit(oldBuffer.capacity());
|
||||
newBuffer.position(0).limit(oldBuffer.capacity());
|
||||
newBuffer.put(oldBuffer);
|
||||
newBuffer.clear();
|
||||
setByteBuffer(newBuffer);
|
||||
|
@ -52,4 +52,15 @@ public class DuplicateByteBufTest extends AbstractByteBufTest {
|
||||
super.testInternalNioBuffer();
|
||||
}
|
||||
|
||||
// See https://github.com/netty/netty/issues/1800
|
||||
@Test
|
||||
public void testIncreaseCapacityWrapped() {
|
||||
ByteBuf wrapped = buffer.unwrap();
|
||||
wrapped.writeByte(0);
|
||||
wrapped.readerIndex(wrapped.readerIndex() + 1);
|
||||
buffer.writerIndex(buffer.writerIndex() + 1);
|
||||
wrapped.capacity(wrapped.capacity() * 2);
|
||||
|
||||
assertEquals((byte) 0, buffer.readByte());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user