FIX endless loop in ByteBufUtil#writeAscii

Motivation:

Missing return in ByteBufUtil#writeAscii causes endless loop

Modifications:

Add return after write finished

Result:

ByteBufUtil#writeAscii is ok
This commit is contained in:
louyl 2017-08-12 15:46:55 +08:00 committed by Norman Maurer
parent 08284dbbcd
commit 8be9a63c1c
2 changed files with 17 additions and 1 deletions

View File

@ -591,7 +591,9 @@ public final class ByteBufUtil {
// Unwrap as the wrapped buffer may be an AbstractByteBuf and so we can use fast-path.
buf = buf.unwrap();
} else {
buf.writeBytes(seq.toString().getBytes(CharsetUtil.US_ASCII));
byte[] bytes = seq.toString().getBytes(CharsetUtil.US_ASCII);
buf.writeBytes(bytes);
return bytes.length;
}
}
}

View File

@ -204,6 +204,20 @@ public class ByteBufUtilTest {
buf2.release();
}
@Test
public void testWriteUsAsciiSwapped() {
String usAscii = "NettyRocks";
ByteBuf buf = Unpooled.buffer(16);
buf.writeBytes(usAscii.getBytes(CharsetUtil.US_ASCII));
SwappedByteBuf buf2 = new SwappedByteBuf(Unpooled.buffer(16));
ByteBufUtil.writeAscii(buf2, usAscii);
assertEquals(buf, buf2);
buf.release();
buf2.release();
}
@Test
public void testWriteUsAsciiWrapped() {
String usAscii = "NettyRocks";