NETTY-425 ChannelBuffers.compare does not handle unsigned bytes correctly

* Fixed a bug where signed comparison is made where unsigned comparison is expected
This commit is contained in:
Trustin Lee 2011-08-01 04:28:08 +09:00
parent fba8c7b7a4
commit 2d35bf2155
2 changed files with 15 additions and 2 deletions

View File

@ -995,8 +995,8 @@ public class ChannelBuffers {
}
for (int i = byteCount; i > 0; i --) {
byte va = bufferA.getByte(aIndex);
byte vb = bufferB.getByte(bIndex);
short va = bufferA.getUnsignedByte(aIndex);
short vb = bufferB.getUnsignedByte(bIndex);
if (va > vb) {
return 1;
} else if (va < vb) {

View File

@ -200,6 +200,19 @@ public class ChannelBuffersTest {
assertSame(EMPTY_BUFFER, copiedBuffer(new ChannelBuffer[] { buffer(0), buffer(0) }));
}
@Test
public void testCompare2() {
assertTrue(ChannelBuffers.compare(
ChannelBuffers.wrappedBuffer(new byte[]{(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}),
ChannelBuffers.wrappedBuffer(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}))
> 0);
assertTrue(ChannelBuffers.compare(
ChannelBuffers.wrappedBuffer(new byte[]{(byte) 0xFF}),
ChannelBuffers.wrappedBuffer(new byte[]{(byte) 0x00}))
> 0);
}
@Test(expected = NullPointerException.class)
public void shouldDisallowNullEndian1() {
buffer(null, 0);