When a ':s' search and replace command had an empty replacement
string a subsequent undo put the original text in the wrong place.

Fix this by skipping the insertion of an empty replacement string.

function                                             old     new   delta
colon                                               4024    4036     +12

Signed-off-by: Ron Yorston <[email protected]>
---
 editors/vi.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/editors/vi.c b/editors/vi.c
index f0bbc9518..7cbeb7113 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -3139,12 +3139,14 @@ static void colon(char *buf)
                                        ++lines;
                                }
 #  endif
-                               // insert the "replace" patern
-                               bias = string_insert(found, R, 
ALLOW_UNDO_CHAIN);
-                               found += bias;
-                               ls += bias;
+                               // insert the "replace" pattern, if required
+                               if (len_R) {
+                                       bias = string_insert(found, R, 
ALLOW_UNDO_CHAIN);
+                                       found += bias;
+                                       ls += bias;
+                                       //q += bias; - recalculated anyway
+                               }
                                dot = ls;
-                               //q += bias; - recalculated anyway
                                // check for "global"  :s/foo/bar/g
                                if (gflag == 'g') {
                                        if ((found + len_R) < end_line(ls)) {
-- 
2.31.1

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to