Don't construct zero length big integer

This commit is contained in:
DBotThePony 2022-08-16 18:35:48 +07:00
parent 3952067366
commit add14f1733
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -607,9 +607,14 @@ class ImpreciseFraction @JvmOverloads constructor(whole: BigInteger, decimal: Do
@JvmStatic
fun fromByteArray(input: ByteArray): ImpreciseFraction {
val size = unsignedInt(input[0])
if (size > 0) {
val slice = input.copyOfRange(1, 1 + size)
val bits = bytesToLongBE(input, 1 + size)
return ImpreciseFraction(BigInteger(slice), Double.fromBits(bits))
} else {
return ImpreciseFraction(BigInteger.ZERO, Double.fromBits(bytesToLongBE(input, 1)))
}
}
@JvmStatic