on master help sign in
Reset the lazy decoder state consistently if an error occurs
2925921Bryan O'Sullivan
Data/Text/Encoding.hs+1−1
@@ -267,6 +267,7 @@ streamDecodeUtf8With onErr = decodeChunk B.empty 0 0
267 UTF8_REJECT -> do
267 UTF8_REJECT -> do
268 -- We encountered an encoding error
268 -- We encountered an encoding error
269 x <- peek curPtr'
269 x <- peek curPtr'
270+ poke statePtr 0
270 case onErr desc (Just x) of
271 case onErr desc (Just x) of
271 Nothing -> loop $ curPtr' `plusPtr` 1
272 Nothing -> loop $ curPtr' `plusPtr` 1
272 Just c -> do
273 Just c -> do
@@ -274,7 +275,6 @@ streamDecodeUtf8With onErr = decodeChunk B.empty 0 0
274 w <- unsafeSTToIO $
275 w <- unsafeSTToIO $
275 unsafeWrite dest (fromIntegral destOff) (safe c)
276 unsafeWrite dest (fromIntegral destOff) (safe c)
276 poke destOffPtr (destOff + fromIntegral w)
277 poke destOffPtr (destOff + fromIntegral w)
277− poke statePtr 0
278 loop $ curPtr' `plusPtr` 1
278 loop $ curPtr' `plusPtr` 1
279
279
280 _ -> do
280 _ -> do