Subject: Re: sed cannot substitute more than 4kB
To: Emmanuel Dreyfus <manu@NetBSD.org>
From: Jaromir Dolecek <jdolecek@NetBSD.org>
List: tech-userlevel
Date: 07/09/2004 10:57:17
Emmanuel Dreyfus wrote:
> Hi
> 
> Here is a sed bug:
> echo "X"|sed "s/X/`jot -sx -bx 2048`/"
> 
> i.e.: it cannot substitute by a string bigger than 4096kB
> 
> Here is a fix:
> 
> Index: compile.c
> ===================================================================
> RCS file: /cvsroot/src/usr.bin/sed/compile.c,v
> retrieving revision 1.28
> diff -U4 -r1.28 compile.c
> --- compile.c   13 Jun 2004 08:34:31 -0000      1.28
> +++ compile.c   9 Jul 2004 08:09:17 -0000
> @@ -543,9 +543,9 @@
>                 }
>                 size += sp - op;
>                 if (asize - size < _POSIX2_LINE_MAX + 1) {
>                         asize *= 2;
> -                       text = xmalloc(asize);
> +                       text = xrealloc(text, asize);
>                 }
>         } while (cu_fgets(p = lbuf, sizeof(lbuf)));
>         err(COMPILE, "unterminated substitute in regular expression");
>         /* NOTREACHED */
> 
> 
> Is it okay to commit that? To pull-it up to 2.0 and 1.6?

Sure. This is obvious bug.

Jaromir 
> 
> -- 
> Emmanuel Dreyfus
> manu@netbsd.org
> 

-- 
Jaromir Dolecek <jdolecek@NetBSD.org>            http://www.NetBSD.cz/
-=- We should be mindful of the potential goal, but as the Buddhist -=-
-=- masters say, ``You may notice during meditation that you        -=-
-=- sometimes levitate or glow.   Do not let this distract you.''   -=-