mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-07 15:50:57 +03:00
add Buffer capacity check for type UInt64 (#454)
This commit is contained in:
committed by
Jeroen van Erp
parent
4de9f8ab9f
commit
17c368f9c2
@@ -372,6 +372,7 @@ public class Buffer<T extends Buffer<T>> {
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private T putUInt64Unchecked(long uint64) {
|
private T putUInt64Unchecked(long uint64) {
|
||||||
|
ensureCapacity(8);
|
||||||
data[wpos++] = (byte) (uint64 >> 56);
|
data[wpos++] = (byte) (uint64 >> 56);
|
||||||
data[wpos++] = (byte) (uint64 >> 48);
|
data[wpos++] = (byte) (uint64 >> 48);
|
||||||
data[wpos++] = (byte) (uint64 >> 40);
|
data[wpos++] = (byte) (uint64 >> 40);
|
||||||
|
|||||||
@@ -146,4 +146,28 @@ public class BufferTest {
|
|||||||
assertArrayEquals("Value: " + value, bytesLong, bytesBigInt);
|
assertArrayEquals("Value: " + value, bytesLong, bytesBigInt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldExpandCapacityOfUInt32(){
|
||||||
|
PlainBuffer buf = new PlainBuffer();
|
||||||
|
for(int i=0;i<Buffer.DEFAULT_SIZE+1;i+=4) {
|
||||||
|
buf.putUInt32(1l);
|
||||||
|
}
|
||||||
|
/* Buffer should have been expanded at this point*/
|
||||||
|
assertEquals(Buffer.DEFAULT_SIZE*2,buf.data.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldExpandCapacityOfUInt64(){
|
||||||
|
BigInteger bigUint64 = BigInteger.valueOf(Long.MAX_VALUE);
|
||||||
|
PlainBuffer buf = new PlainBuffer();
|
||||||
|
assertEquals(Buffer.DEFAULT_SIZE,buf.data.length);
|
||||||
|
for(int i=0;i<Buffer.DEFAULT_SIZE+1;i+=8) {
|
||||||
|
buf.putUInt64(bigUint64.longValue());
|
||||||
|
}
|
||||||
|
/* Buffer should have been expanded at this point*/
|
||||||
|
assertEquals(Buffer.DEFAULT_SIZE*2,buf.data.length);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user