[Toybox] pathological case in sed s///g

Rob Landley rob at landley.net
Fri May 3 10:40:34 PDT 2019


On 5/2/19 9:46 PM, enh via Toybox wrote:
> i've known about this for a couple of days and haven't had time to
> look at it properly yet, so i should mention it here...
> 
> if you have a file with a 1MiB line of 'x'es and you sed 's/x/y/g',
> BSD or GNU sed finishes immediately, but toybox takes forever.

Because it allocates a replacement string and copies the before/replace/after
parts into it for each replacement. I should switch the xmalloc() on line 515 to
xrealloc() and fiddle with the surrounding code not to do unnecessary work...

Rob



More information about the Toybox mailing list