From 4d2fa4ea4c3a7a447a24f48b8c4f100aa298aaa8 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sun, 15 Jun 2014 19:13:42 +0200 Subject: [PATCH] small bugfix in CCArray.Sub: bound checking --- core/CCArray.ml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/CCArray.ml b/core/CCArray.ml index 10fe36e6..b63f8671 100644 --- a/core/CCArray.ml +++ b/core/CCArray.ml @@ -374,9 +374,15 @@ module Sub = struct let foldi f acc a = _foldi f acc a.arr a.i a.j - let get a i = a.arr.(a.i+i) + let get a i = + let j = a.i + i in + if i<0 || j>=a.j then invalid_arg "Array.Sub.get"; + a.arr.(j) - let set a i x = a.arr.(a.i+i) <- x + let set a i x = + let j = a.i + i in + if i<0 || j>=a.j then invalid_arg "Array.Sub.get"; + a.arr.(j) <- x let iter f a = for k=a.i to a.j-1 do f a.arr.(k) done