aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2026-02-06 22:56:16 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2026-02-06 22:56:16 +0100
commit3620c4ee677224aed6d6fa02aa8d034b4495370e (patch)
tree1fc2c0547995549ba2598a4c2d7f78079562b9b2 /editors
parent80ce9e3998dc07d8c4653daa7265df09145b9c13 (diff)
downloadbusybox-w32-3620c4ee677224aed6d6fa02aa8d034b4495370e.tar.gz
busybox-w32-3620c4ee677224aed6d6fa02aa8d034b4495370e.tar.bz2
busybox-w32-3620c4ee677224aed6d6fa02aa8d034b4495370e.zip
vi: fix "s /find/repl" with whitespace before /
function old new delta colon 3977 4005 +28 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors')
-rw-r--r--editors/vi.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/editors/vi.c b/editors/vi.c
index 5bc180b5d..814a63a7b 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -2850,7 +2850,7 @@ static void colon(char *buf)
2850 not_implemented(p); 2850 not_implemented(p);
2851#else 2851#else
2852 char c, *q, *r; 2852 char c, *q, *r;
2853 char *fn, cmd[MAX_INPUT_LEN], *cmdend, *args; 2853 char *fn, cmd[MAX_INPUT_LEN], *args;
2854 char *exp = NULL; 2854 char *exp = NULL;
2855 char *useforce; 2855 char *useforce;
2856 int cmdlen; 2856 int cmdlen;
@@ -2890,15 +2890,14 @@ static void colon(char *buf)
2890 goto ret; 2890 goto ret;
2891 2891
2892 // get the COMMAND into cmd[] 2892 // get the COMMAND into cmd[]
2893 strcpy(cmd, buf); 2893 args = skip_non_whitespace(buf);
2894 cmdend = skip_non_whitespace(cmd); 2894 safe_strncpy(cmd, buf, (args - buf) + 1);
2895 // get any ARGuments 2895//NB: in "s/find/repl" and "!CMD" cases, we copy unnecessary data into buf[]
2896 args = skip_whitespace(cmdend);
2897//NB: arguments can be accessed in buf[] as well, there is no need to copy them into cmd[]?
2898 *cmdend = '\0';
2899 useforce = last_char_is(cmd, '!'); 2896 useforce = last_char_is(cmd, '!');
2900 if (useforce && useforce > cmd) 2897 if (useforce && useforce > cmd)
2901 *useforce = '\0'; // "CMD!" -> "CMD" (unless single "!") 2898 *useforce = '\0'; // "CMD!" -> "CMD" (unless single "!")
2899 // find ARGuments
2900 args = skip_whitespace(args);
2902 2901
2903 // assume the command will want a range, certain commands 2902 // assume the command will want a range, certain commands
2904 // (read, substitute) need to adjust these assumptions 2903 // (read, substitute) need to adjust these assumptions
@@ -3151,7 +3150,9 @@ static void colon(char *buf)
3151 editing = 0; 3150 editing = 0;
3152 } 3151 }
3153# if ENABLE_FEATURE_VI_SET 3152# if ENABLE_FEATURE_VI_SET
3154 } else if (strncmp(cmd, "set", cmdlen) == 0) { // set or clear features 3153 } else if (strncmp(cmd, "set", cmdlen) == 0 // set or clear features
3154 IF_FEATURE_VI_SEARCH(&& cmdlen > 1) // (do not confuse with "s /find/repl/")
3155 ) {
3155# if ENABLE_FEATURE_VI_SETOPTS 3156# if ENABLE_FEATURE_VI_SETOPTS
3156 char *argp, *argn, oldch; 3157 char *argp, *argn, oldch;
3157# endif 3158# endif
@@ -3210,12 +3211,12 @@ static void colon(char *buf)
3210 int undo = 0; 3211 int undo = 0;
3211# endif 3212# endif
3212# endif 3213# endif
3213 3214 buf = skip_whitespace(buf + 1); // spaces allowed: "s /find/repl/"
3214 // F points to the "find" pattern 3215 // F points to the "find" pattern
3215 // R points to the "replace" pattern 3216 // R points to the "replace" pattern
3216 // replace the cmd line delimiters "/" with NULs 3217 // replace the cmd line delimiters "/" with NULs
3217 c = buf[1]; // what is the delimiter 3218 c = buf[0]; // what is the delimiter
3218 F = buf + 2; // start of "find" 3219 F = buf + 1; // start of "find"
3219 R = strchr_backslash(F, c); // middle delimiter 3220 R = strchr_backslash(F, c); // middle delimiter
3220 if (!R) 3221 if (!R)
3221 goto colon_s_fail; 3222 goto colon_s_fail;