From: Ian Lynagh Date: Sun, 19 Jul 2009 15:32:28 +0000 (+0000) Subject: Improve the index checking for array accesses; fixes #2120 #2669 X-Git-Tag: ghc-darcs-git-switchover~345 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=9cac65ea790d47f5ad32da0695a5c85ee788cbba;p=ghc-base.git Improve the index checking for array accesses; fixes #2120 #2669 As well as checking that offset we are reading is actually inside the array, we now also check that it is "in range" as defined by the Ix instance. This fixes confusing behaviour (#2120) and improves some error messages (#2669). --- diff --git a/GHC/Arr.lhs b/GHC/Arr.lhs index dbd7975..7dd0e90 100644 --- a/GHC/Arr.lhs +++ b/GHC/Arr.lhs @@ -435,10 +435,11 @@ safeRangeSize (l,u) = let r = rangeSize (l, u) {-# INLINE safeIndex #-} safeIndex :: Ix i => (i, i) -> Int -> i -> Int -safeIndex (l,u) n i = let i' = unsafeIndex (l,u) i +safeIndex (l,u) n i = let i' = index (l,u) i in if (0 <= i') && (i' < n) then i' - else error "Error in array index" + else error ("Error in array index; " ++ show i' ++ + " not in range [0.." ++ show n ++ ")") {-# INLINE unsafeAt #-} unsafeAt :: Ix i => Array i e -> Int -> e