git.iko.soy/typeable/attoparsec
on master help sign in
bytestring: ensure that -ve args to take are safe

This fixes bug #37.

commit666b0a7d3bdbd211332911b99df31345c664fa87 authorBryan O'Sullivan <bos@serpentine.com> dateWed 23 Jan 2013, 20:42 (14 years ago) parentc78b7eb
1 file changed+2−1
Data/Attoparsec/ByteString/Internal.hs+2−1
Data/Attoparsec/ByteString/Internal.hs+2−1
@@ -218,7 +218,8 @@ storable = hack undefined
218218-- | Consume @n@ bytes of input, but succeed only if the predicate
219219-- returns 'True'.
220220takeWith :: Int -> (B.ByteString -> Bool) -> Parser B.ByteString
221−takeWith n p = do
221+takeWith n0 p = do
222+ let n = max n0 0
222223 s <- ensure n
223224 let h = B.unsafeTake n s
224225 t = B.unsafeDrop n s