Bounds check for writeCharArray#
This commit is contained in:
parent
1fc4a1faba
commit
3e8e438109
3 changed files with 19 additions and 1 deletions
|
@ -1 +0,0 @@
|
|||
packages: .
|
14
src-checked/Op.hs
Normal file
14
src-checked/Op.hs
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Op
|
||||
( writeCharArray#
|
||||
) where
|
||||
|
||||
import GHC.Exts ((<#),(>=#))
|
||||
import qualified GHC.Exts as Exts
|
||||
|
||||
writeCharArray# :: Exts.MutableByteArray# s -> Exts.Int# -> Exts.Char# -> Exts.State# s -> Exts.State# s
|
||||
writeCharArray# arr i v st = case i <# 0# of
|
||||
1# -> error ("writeCharArray#: negative index " ++ show (I# i))
|
||||
_ -> case Exts.getSizeofMutableByteArray# arr st of
|
||||
(# st', sz #) -> case i >=# sz of
|
||||
1# -> error ("writeCharArray#: index " ++ show (I# i) ++ " >= length " ++ show (I# sz))
|
||||
_ -> Exts.writeInt8Array# arr i (Exts.intToInt8# v) st'
|
5
src-unchecked/Op.hs
Normal file
5
src-unchecked/Op.hs
Normal file
|
@ -0,0 +1,5 @@
|
|||
module Op
|
||||
( writeCharArray#
|
||||
) where
|
||||
|
||||
import GHC.Exts (writeCharArray#)
|
Loading…
Reference in a new issue