diff --git a/lib/bap_image/bap_memory.ml b/lib/bap_image/bap_memory.ml index 4ae736db9..6ad08e4b2 100644 --- a/lib/bap_image/bap_memory.ml +++ b/lib/bap_image/bap_memory.ml @@ -213,7 +213,7 @@ module Input = struct let int256 = read `r256 end -let view_exn ?(word_size=`r8) ?from ?words t = +let view_exn ?(word_size=`r8) ?from ?words t = let amin = Option.value from ~default:(min_addr t) in let amax = match words with | None -> max_addr t @@ -225,7 +225,7 @@ let view_exn ?(word_size=`r8) ?from ?words t = if off >= t.off && off < t.off + t.size then match size with | 0 -> invalid_arg "empty view" | 1 -> make_byte t amin off - | n when n <= t.size -> + | n when n <= t.size && off + size <= t.off + t.size -> { t with size; data = t.data; addr = amin; off} | _ -> invalid_arg "out-of-bounds" else invalid_arg "out-of-bounds" @@ -354,12 +354,12 @@ module Make_iterators( M : Monad.S) = struct let find_map ?word_size t ~f = with_return (fun s -> - iteri t ~f:(fun a w -> f a w >>= function + iteri ?word_size t ~f:(fun a w -> f a w >>= function | None -> return () | some -> s.return (return some)) >>| fun () -> None) let find_if ?word_size t ~f = - find_map t ~f:(fun a w -> f a w >>| function + find_map ?word_size t ~f:(fun a w -> f a w >>| function | true -> Some w | false -> None) end