Bug 15166 - Bug in substitution function of the ed applet
Summary: Bug in substitution function of the ed applet
Status: NEW
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.34.x
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-12-06 23:21 UTC by rozel
Modified: 2022-12-06 23:24 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.