diff options
| -rw-r--r-- | editors/vi.c | 23 | ||||
| -rw-r--r-- | include/libbb.h | 2 |
2 files changed, 14 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; |
diff --git a/include/libbb.h b/include/libbb.h index 6ce01ea94..baf0f29e5 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
| @@ -939,6 +939,8 @@ int parse_pasv_epsv(char *buf) FAST_FUNC; | |||
| 939 | /* 0 if argv[0] is NULL: */ | 939 | /* 0 if argv[0] is NULL: */ |
| 940 | unsigned string_array_len(char **argv) FAST_FUNC; | 940 | unsigned string_array_len(char **argv) FAST_FUNC; |
| 941 | void overlapping_strcpy(char *dst, const char *src) FAST_FUNC; | 941 | void overlapping_strcpy(char *dst, const char *src) FAST_FUNC; |
| 942 | /* Like strncpy but make sure the resulting string is always 0 terminated: */ | ||
| 943 | /* writes SIZE chars, the [SIZE-1] char is always NUL (unless SIZE==0). */ | ||
| 942 | char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC; | 944 | char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC; |
| 943 | char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC; | 945 | char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC; |
| 944 | unsigned count_strstr(const char *str, const char *sub) FAST_FUNC; | 946 | unsigned count_strstr(const char *str, const char *sub) FAST_FUNC; |
