Commits

Bryan O'Sullivan committed 5cd2fde

indices: Eliminate a read past the end of the array

Comments (0)

Files changed (1)

Data/Text/Search.hs

     z        = nindex nlast
     nindex k = A.unsafeIndex narr (noff+k)
     hindex k = A.unsafeIndex harr (hoff+k)
+    hindex' k | k == hlen  = 0
+              | otherwise = A.unsafeIndex harr (hoff+k)
     (mask :: Word64) :*: skip  = buildTable 0 0 (nlen-2)
     buildTable !i !msk !skp
         | i >= nlast           = (msk .|. swizzle z) :*: skp
               delta | nextInPattern = nlen + 1
                     | c == z        = skip + 1
                     | otherwise     = 1
-              nextInPattern         = mask .&. swizzle (hindex (i+nlen)) == 0
+              nextInPattern         = mask .&. swizzle (hindex' (i+nlen)) == 0
     scanOne c = loop 0
         where loop !i | i >= hlen     = []
                       | hindex i == c = i : loop (i+1)