on master help sign in
Use mul for replace, to avoid overflow

This fixes gh-81.

commit466172d7397d9ed783c97f35fd31aa06ae4c1bec authorBryan O'Sullivan <bos@serpentine.com> dateFri 6 Jun 2014, 00:35 (12 years ago) parenta2408d1
1 file changed+2−3
Data/Text.hs+2−3
Data/Text.hs+2−3
@@ -213,7 +213,7 @@ import qualified Data.Text.Internal.Fusion as S
213213import qualified Data.Text.Internal.Fusion.Common as S
214214import Data.Text.Internal.Fusion (stream, reverseStream, unstream)
215215import Data.Text.Internal.Private (span_)
216−import Data.Text.Internal (Text(..), empty, firstf, safe, text)
216+import Data.Text.Internal (Text(..), empty, firstf, mul, safe, text)
217217import qualified Prelude as P
218218import Data.Text.Unsafe (Iter(..), iter, iter_, lengthWord16, reverseIter,
219219 reverseIter_, unsafeHead, unsafeTail)
@@ -638,11 +638,10 @@ replace needle@(Text _ _ neeLen)
638638 | neeLen == 0 = emptyError "replace"
639639 | L.null ixs = haystack
640640 | len > 0 = Text (A.run x) 0 len
641− | len < 0 = overflowError "replace"
642641 | otherwise = empty
643642 where
644643 ixs = indices needle haystack
645− len = hayLen - (neeLen - repLen) * L.length ixs
644+ len = hayLen - (neeLen - repLen) `mul` L.length ixs
646645 x = do
647646 marr <- A.new len
648647 let loop (i:is) o d = do