Skip to content

Commit 101f796

Browse files
Fix max_length overflow on 32 bits integer platform.
JS has 32 bits integer. When multiplying by 8 it overflows and the length becomes negative.
1 parent f30e7a8 commit 101f796

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

bitv.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ let length v = v.length
3636

3737
let[@inline] equal (v1: t) (v2: t) = v1 = v2
3838

39-
let max_length = Sys.max_string_length * 8
39+
let max_length =
40+
let n = Sys.max_string_length * 8 in
41+
(* We use 64 bits because it can overflow on architecture
42+
with 32 bits integer like JS for instance. *)
43+
if n < 0 then max_int else n
4044

4145
let exceeds_max_length n =
4246
let s = n / 8 in

0 commit comments

Comments
 (0)