Assert length is multiple of elemSize

This commit is contained in:
Harendra Kumar 2021-10-10 19:09:01 +05:30
parent f700973876
commit e870b5cdb7

View File

@ -455,7 +455,10 @@ byteLength Array{..} =
-- @since 0.7.0
{-# INLINE length #-}
length :: forall a. Storable a => Array a -> Int
length arr = byteLength arr `div` sizeOf (undefined :: a)
length arr =
let elemSize = sizeOf (undefined :: a)
blen = byteLength arr
in assert (blen `mod` elemSize == 0) (blen `div` elemSize)
-- | Get the total capacity of an array. An array may have space reserved
-- beyond the current used length of the array.