We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 59c7750 commit 0d83927Copy full SHA for 0d83927
Data/Vector/Primitive/Mutable.hs
@@ -90,8 +90,13 @@ instance Prim a => G.MVector MVector a where
90
between x y z = x >= y && x < z
91
92
{-# INLINE basicUnsafeNew #-}
93
- basicUnsafeNew n = MVector 0 n
94
- `liftM` newByteArray (n * sizeOf (undefined :: a))
+ basicUnsafeNew n
+ | n < 0 = error $ "Primitive.basicUnsafeNew: negative length: " ++ show n
95
+ | n > mx = error $ "Primitive.basicUnsafeNew: length to large: " ++ show n
96
+ | otherwise = MVector 0 n `liftM` newByteArray (n * size)
97
+ where
98
+ size = sizeOf (undefined :: a)
99
+ mx = maxBound `div` size :: Int
100
101
{-# INLINE basicUnsafeRead #-}
102
basicUnsafeRead (MVector i _ arr) j = readByteArray arr (i+j)
0 commit comments