Bug 15166

Summary: Bug in substitution function of the ed applet
Product: Busybox Reporter: rozel
Component: OtherAssignee: unassigned
Status: NEW ---    
Severity: normal CC: busybox-cvs, rozel
Priority: P5    
Version: 1.34.x   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:

Description rozel 2022-12-06 23:21:46 UTC
Non global substitution isn't done in two consecutive lines when the string on the 2nd line is before or at the same place of the first line.
For example :

,s/OLD/NEW/ on 
--
OLD
OLD
--
 gave 
--
OLD
NEW
--
(bug)

but on
--
OLD

OLD
--
 gave
--
NEW

NEW
--
(OK)

and on 
--
OLD
XXXOLD
--
(OK)

gave 
--
NEW
XXXNEW
--
(OK).

On the first example, ,s/OLD/NEW/g works correctly (all OLD are substituted).

Looking at the source of the 1.35 version (editors/ed.c), it seems that this problem can be corrected by initializing "offset = 0;" each time "lp = lp->next; num1++;" in the subCommand() function (so in line 729 and 770).
Comment 1 rozel 2022-12-06 23:24:54 UTC
Please read
--
NEW
OLD
--

instead the opposite for the erroneous behavior.
Sorry.