We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 1eb5637 + dd2c1e8 commit 7d180aaCopy full SHA for 7d180aa
1 file changed
Data/Vector/Storable/Mutable.hs
@@ -117,10 +117,14 @@ instance Storable a => G.MVector MVector a where
117
118
{-# INLINE basicUnsafeNew #-}
119
basicUnsafeNew n
120
- = unsafePrimToPrim
121
- $ do
+ | n < 0 = error $ "Storable.basicUnsafeNew: negative length: " ++ show n
+ | n > mx = error $ "Storable.basicUnsafeNew: length too large: " ++ show n
122
+ | otherwise = unsafePrimToPrim $ do
123
fp <- mallocVector n
124
return $ MVector n fp
125
+ where
126
+ size = sizeOf (undefined :: a)
127
+ mx = maxBound `quot` size :: Int
128
129
{-# INLINE basicInitialize #-}
130
basicInitialize = storableZero
0 commit comments