Skip to content

Commit

Permalink
Bugfix for shift count limits
Browse files Browse the repository at this point in the history
32-bit shifts in OCaml must have a shift count < 32, not <= 32.
  • Loading branch information
stedolan committed Sep 23, 2022
1 parent 69ec075 commit dbffd75
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions dune-workspace.all
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
(context (opam (switch 4.13.1) ))
(context (opam (switch 4.13.1+flambda)))
(context (opam (switch 4.14.0) ))
(context (opam (switch 4.14.0+32bit) ))
(context (opam (switch 4.14.0+flambda)))
2 changes: 1 addition & 1 deletion src/malfunction_interpreter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ let rec interpret locals env : t -> value = function
| `Bigint -> ()
| (`Int|`Int32|`Int64) as ty ->
let w = bitwidth ty in
if c < 0 || c > w then
if c < 0 || c >= w then
fail "invalid shift count %d" c in
truncate ty Z.(match op with
| `Lsl -> shift_left n c
Expand Down
7 changes: 3 additions & 4 deletions test/shifts.test
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
(test-undefined (>> 1 113455345))
(test-undefined (a>> 1 113455345))

(test (<<.i32 1.i32 32) 0.i32)
(test-undefined (<<.i32 1.i32 33))
(test (<<.i32 1.i32 31) -2147483648.i32)
(test-undefined (<<.i32 1.i32 32))
(test (>>.i32 (neg.i32 1.i32) 31) 1.i32)
(test (>>.i32 (neg.i32 1.i32) 32) 0.i32)
(test-undefined (>>.i32 (neg.i32 1.i32) 33))
(test-undefined (>>.i32 (neg.i32 1.i32) 32))

0 comments on commit dbffd75

Please sign in to comment.