Skip to content

Commit

Permalink
add upper bounds for u64 number since numbers can be larger than MAX_…
Browse files Browse the repository at this point in the history
…SAFE_INTEGER
  • Loading branch information
marcus-pousette committed Jan 15, 2023
1 parent d9979aa commit ada6ef6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions benchmark/u64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import protobuf from "protobufjs";
// This benchmark is not that good since protobufjs convert bigints into LongBit format rather than bigint on deserialization

/*
* borsh bigint x 5,326,970 ops/sec ±0.37% (395 runs sampled)
* protobujs bigint x 6,904,183 ops/sec ±0.42% (392 runs sampled)
* borsh number x 6,350,140 ops/sec ±0.30% (394 runs sampled)
* protobujs number x 5,152,453 ops/sec ±0.41% (394 runs sampled)
* borsh bigint x 5,385,093 ops/sec ±0.44% (389 runs sampled)
* protobujs bigint x 7,022,500 ops/sec ±0.53% (393 runs sampled)
* borsh number x 6,124,037 ops/sec ±0.42% (393 runs sampled)
* protobujs number x 4,639,581 ops/sec ±0.35% (394 runs sampled)
*/

function getRandomInt(max: number) {
Expand Down
2 changes: 1 addition & 1 deletion src/bigint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const writeBigUint64Le = (bigIntOrNumber: bigint | number, buf: Uint8Arra

}
else {
if (bigIntOrNumber < 0) {
if (bigIntOrNumber < 0 || bigIntOrNumber > 18446744073709551615n) {
throw new Error("u64 value can not negative, got " + bigIntOrNumber)
}
// We don't need upper bound check because number can not exceed 18446744073709551615
Expand Down

0 comments on commit ada6ef6

Please sign in to comment.