From 4c76595a02bd6819a5c7c7dca25aa9d3818af045 Mon Sep 17 00:00:00 2001 From: zapashcanon Date: Sat, 16 Sep 2023 14:20:30 +0200 Subject: [PATCH] fix table.get out_of_bounds check (it's better to check before getting the value...) --- src/interpret_functor.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/interpret_functor.ml b/src/interpret_functor.ml index c85574175..23245f56d 100644 --- a/src/interpret_functor.ml +++ b/src/interpret_functor.ml @@ -1025,10 +1025,11 @@ module Make (P : Interpret_functor_intf.P) : let i, stack = Stack.pop_i32 stack in let/ i = Choice.select_i32 i in let i = Int32.to_int i in - let v = Table.get t i in let size = Table.size t in if i < 0 || i >= size then Choice.trap Out_of_bounds_table_access - else st @@ Stack.push stack (Ref v) + else + let v = Table.get t i in + st @@ Stack.push stack (Ref v) | Table_set indice -> let* t = Env.get_table env indice in let/ t in