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:
parent
dfd7b0d6c3
commit
acb1ac84e6
@ -979,8 +979,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) {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user