From 30b29a36e80bfeed50bb6ea618401fe35100490f Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 9 Feb 2023 20:56:30 +0100 Subject: refactor(ui): remove some superfluous ui_flush() calls - mapping has no business saving and restoring the low-level UI cursor. The cursor will be put in a reasonable position after input is processed, chill out. - TUI handles output needed for suspend - vgetc() family of function does flushing --- src/nvim/ex_cmds.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 437a05f61d..ae7abfc5e7 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1507,7 +1507,6 @@ void print_line(linenr_T lnum, int use_number, int list) print_line_no_prefix(lnum, use_number, list); if (save_silent) { msg_putchar('\n'); - ui_flush(); silent_mode = save_silent; } info_message = false; -- cgit From c8c930ea785aa393ebc819139913a9e05f0ccd45 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:24:46 +0100 Subject: refactor: reduce scope of locals as per the style guide (#22206) --- src/nvim/ex_cmds.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index ae7abfc5e7..da78861d87 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -724,7 +724,6 @@ sortend: /// @return FAIL for failure, OK otherwise int do_move(linenr_T line1, linenr_T line2, linenr_T dest) { - char *str; linenr_T l; linenr_T extra; // Num lines added before line1 linenr_T num_lines; // Num lines moved @@ -761,7 +760,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) return FAIL; } for (extra = 0, l = line1; l <= line2; l++) { - str = xstrdup(ml_get(l + extra)); + char *str = xstrdup(ml_get(l + extra)); ml_append(dest + l - line1, str, (colnr_T)0, false); xfree(str); if (dest < line1) { @@ -875,10 +874,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) /// ":copy" void ex_copy(linenr_T line1, linenr_T line2, linenr_T n) { - linenr_T count; - char *p; - - count = line2 - line1 + 1; + linenr_T count = line2 - line1 + 1; if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { curbuf->b_op_start.lnum = n + 1; curbuf->b_op_end.lnum = n + count; @@ -902,7 +898,7 @@ void ex_copy(linenr_T line1, linenr_T line2, linenr_T n) while (line1 <= line2) { // need to use xstrdup() because the line will be unlocked within // ml_append() - p = xstrdup(ml_get(line1)); + char *p = xstrdup(ml_get(line1)); ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, false); xfree(p); @@ -952,7 +948,6 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out char *t; char *p; char *trailarg; - size_t len; int scroll_save = msg_scroll; // @@ -975,7 +970,7 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out // Skip leading white space to avoid a strange error with some shells. trailarg = skipwhite(arg); do { - len = strlen(trailarg) + 1; + size_t len = strlen(trailarg) + 1; if (newcmd != NULL) { len += strlen(newcmd); } @@ -2736,7 +2731,6 @@ void ex_append(exarg_T *eap) linenr_T lnum = eap->line2; int indent = 0; char *p; - int vcol; int empty = (curbuf->b_ml.ml_flags & ML_EMPTY); // the ! flag toggles autoindent @@ -2803,7 +2797,7 @@ void ex_append(exarg_T *eap) } // Look for the "." after automatic indent. - vcol = 0; + int vcol = 0; for (p = theline; indent > vcol; p++) { if (*p == ' ') { vcol++; @@ -4339,7 +4333,6 @@ static void global_exe_one(char *const cmd, const linenr_T lnum) void ex_global(exarg_T *eap) { linenr_T lnum; // line number according to old situation - int ndone = 0; int type; // first char of cmd: 'v' or 'g' char *cmd; // command argument @@ -4411,6 +4404,7 @@ void ex_global(exarg_T *eap) global_exe_one(cmd, lnum); } } else { + int ndone = 0; // pass 1: set marks for each (not) matching line for (lnum = eap->line1; lnum <= eap->line2 && !got_int; lnum++) { // a match on this line? @@ -4687,8 +4681,6 @@ int ex_substitute_preview(exarg_T *eap, long cmdpreview_ns, handle_T cmdpreview_ /// @return a pointer to the char just past the pattern plus flags. char *skip_vimgrep_pat(char *p, char **s, int *flags) { - int c; - if (vim_isIDc((uint8_t)(*p))) { // ":vimgrep pattern fname" if (s != NULL) { @@ -4703,7 +4695,7 @@ char *skip_vimgrep_pat(char *p, char **s, int *flags) if (s != NULL) { *s = p + 1; } - c = (uint8_t)(*p); + int c = (uint8_t)(*p); p = skip_regexp(p + 1, c, true); if (*p != c) { return NULL; -- cgit From 7224c889e0d5d70b99ae377036baa6377c33a568 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:25:24 +0100 Subject: build: enable MSVC level 3 warnings (#21934) MSVC has 4 different warning levels: 1 (severe), 2 (significant), 3 (production quality) and 4 (informational). Enabling level 3 warnings mostly revealed conversion problems, similar to GCC/clang -Wconversion flag. --- src/nvim/ex_cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index da78861d87..036e34431b 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -2939,7 +2939,7 @@ void ex_z(exarg_T *eap) bigness = 2 * curbuf->b_ml.ml_line_count; } - p_window = bigness; + p_window = (int)bigness; if (*kind == '=') { bigness += 2; } -- cgit From 4be6c6cf0ddf5e31d4103cb5df06651ba6f4897b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 11:05:57 +0100 Subject: refactor: replace char_u with char (#21901) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/ex_cmds.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 036e34431b..67d1a1e2f7 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1818,7 +1818,7 @@ int check_overwrite(exarg_T *eap, buf_T *buf, char *fname, char *ffname, int oth if (p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) { char buff[DIALOG_MSG_SIZE]; - dialog_msg((char *)buff, _("Overwrite existing file \"%s\"?"), fname); + dialog_msg(buff, _("Overwrite existing file \"%s\"?"), fname); if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) != VIM_YES) { return FAIL; } @@ -1854,7 +1854,7 @@ int check_overwrite(exarg_T *eap, buf_T *buf, char *fname, char *ffname, int oth if (p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) { char buff[DIALOG_MSG_SIZE]; - dialog_msg((char *)buff, + dialog_msg(buff, _("Swap file \"%s\" exists, overwrite anyway?"), swapname); if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) @@ -1974,11 +1974,11 @@ static int check_readonly(int *forceit, buf_T *buf) char buff[DIALOG_MSG_SIZE]; if (buf->b_p_ro) { - dialog_msg((char *)buff, + dialog_msg(buff, _("'readonly' option is set for \"%s\".\nDo you wish to write anyway?"), buf->b_fname); } else { - dialog_msg((char *)buff, + dialog_msg(buff, _("File permissions of \"%s\" are read-only.\nIt may still be possible to " "write it.\nDo you wish to try?"), buf->b_fname); -- cgit From 419819b6245e120aba8897e3ddea711b2cd0246c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 5 Mar 2023 09:18:42 +0800 Subject: vim-patch:9.0.1380: CTRL-X on 2**64 subtracts two (#22530) Problem: CTRL-X on 2**64 subtracts two. (James McCoy) Solution: Correct computation for large number. (closes vim/vim#12103) https://github.com/vim/vim/commit/5fb78c3fa5c996c08a65431d698bd2c251eef5c7 Co-authored-by: Bram Moolenaar --- src/nvim/ex_cmds.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 67d1a1e2f7..a12c2a15b4 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -580,7 +580,7 @@ void ex_sort(exarg_T *eap) } if (sort_nr || sort_flt) { - // Make sure vim_str2nr doesn't read any digits past the end + // Make sure vim_str2nr() doesn't read any digits past the end // of the match, by temporarily terminating the string there s2 = s + end_col; c = *s2; @@ -605,7 +605,7 @@ void ex_sort(exarg_T *eap) } else { nrs[lnum - eap->line1].st_u.num.is_number = true; vim_str2nr(s, NULL, NULL, sort_what, - &nrs[lnum - eap->line1].st_u.num.value, NULL, 0, false); + &nrs[lnum - eap->line1].st_u.num.value, NULL, 0, false, NULL); } } else { s = skipwhite(p); -- cgit From 846a056744bf458d4376cd7638c94f7c82862046 Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 9 Mar 2023 11:45:20 +0100 Subject: refactor(redraw): make cursor position redraw use the "redraw later" pattern --- src/nvim/ex_cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index a12c2a15b4..d398d3e06e 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3747,6 +3747,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T update_topline(curwin); validate_cursor(); redraw_later(curwin, UPD_SOME_VALID); + show_cursor_info_later(true); update_screen(); highlight_match = false; redraw_later(curwin, UPD_SOME_VALID); @@ -3765,7 +3766,6 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T _("replace with %s (y/n/a/q/l/^E/^Y)?"), sub); msg_no_more = false; msg_scroll = (int)i; - show_cursor_info(true); if (!ui_has(kUIMessages)) { ui_cursor_goto(msg_row, msg_col); } -- cgit From d6ecead36406233cc56353dd05f3380f0497630f Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 14 Mar 2023 11:49:46 +0100 Subject: refactor(screen): screen.c delenda est drawscreen.c vs screen.c makes absolutely no sense. The screen exists only to draw upon it, therefore helper functions are distributed randomly between screen.c and the file that does the redrawing. In addition screen.c does a lot of drawing on the screen. It made more sense for vim/vim as our grid.c is their screen.c Not sure if we want to dump all the code for option chars into optionstr.c, so keep these in a optionchar.c for now. --- src/nvim/ex_cmds.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index d398d3e06e..ac3c8c4f8e 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -77,7 +77,6 @@ #include "nvim/profile.h" #include "nvim/quickfix.h" #include "nvim/regexp.h" -#include "nvim/screen.h" #include "nvim/search.h" #include "nvim/spell.h" #include "nvim/strings.h" @@ -2658,7 +2657,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum msg_scroll = false; } if (!msg_scroll) { // wait a bit when overwriting an error msg - check_for_delay(false); + msg_check_for_delay(false); } msg_start(); msg_scroll = msg_scroll_save; -- cgit From d5f6176e6dc4b4e12fc5061ca6e87f4af533e46a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Sat, 1 Apr 2023 02:49:51 +0200 Subject: refactor: add const and remove unnecessary casts (#22841) --- src/nvim/ex_cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index ac3c8c4f8e..621cb764f4 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -4742,7 +4742,7 @@ void ex_oldfiles(exarg_T *eap) } nr++; const char *fname = tv_get_string(TV_LIST_ITEM_TV(li)); - if (!message_filtered((char *)fname)) { + if (!message_filtered(fname)) { msg_outnum(nr); msg_puts(": "); msg_outtrans((char *)tv_get_string(TV_LIST_ITEM_TV(li))); -- cgit From d510bfbc8e447b1a60d5ec7faaa8f440eb4ef56f Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 2 Apr 2023 10:11:42 +0200 Subject: refactor: remove char_u (#22829) Closes https://github.com/neovim/neovim/issues/459 --- src/nvim/ex_cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 621cb764f4..705f0fe83d 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -149,7 +149,7 @@ void do_ascii(const exarg_T *const eap) char buf1[20]; if (vim_isprintc_strict(c) && (c < ' ' || c > '~')) { char buf3[7]; - transchar_nonprint(curbuf, (char_u *)buf3, c); + transchar_nonprint(curbuf, buf3, c); vim_snprintf(buf1, sizeof(buf1), " <%s>", (char *)buf3); } else { buf1[0] = NUL; -- cgit From 1d2a29f75ba7d094c8e7444c9b249a4a7211c93c Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:39:04 +0200 Subject: refactor: make char * parameters const in message.c Add const to char * parameters in message.c functions and remove some redundant casts. --- src/nvim/ex_cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 705f0fe83d..ace254c2c9 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -4745,7 +4745,7 @@ void ex_oldfiles(exarg_T *eap) if (!message_filtered(fname)) { msg_outnum(nr); msg_puts(": "); - msg_outtrans((char *)tv_get_string(TV_LIST_ITEM_TV(li))); + msg_outtrans(tv_get_string(TV_LIST_ITEM_TV(li))); msg_clr_eos(); msg_putchar('\n'); os_breakcheck(); -- cgit From 9408f2dcf7cade2631688300e9b58eed6bc5219a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:40:57 +0200 Subject: refactor: remove redundant const char * casts --- src/nvim/ex_cmds.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index ace254c2c9..a67a01bcea 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1388,7 +1388,7 @@ char *make_filter_cmd(char *cmd, char *itmp, char *otmp) if (is_pwsh) { if (itmp != NULL) { xstrlcpy(buf, "& { Get-Content ", len - 1); // FIXME: should we add "-Encoding utf8"? - xstrlcat(buf, (const char *)itmp, len - 1); + xstrlcat(buf, itmp, len - 1); xstrlcat(buf, " | & ", len - 1); // FIXME: add `&` ourself or leave to user? xstrlcat(buf, cmd, len - 1); xstrlcat(buf, " }", len - 1); @@ -1409,7 +1409,7 @@ char *make_filter_cmd(char *cmd, char *itmp, char *otmp) if (itmp != NULL) { xstrlcat(buf, " < ", len - 1); - xstrlcat(buf, (const char *)itmp, len - 1); + xstrlcat(buf, itmp, len - 1); } #else // For shells that don't understand braces around commands, at least allow @@ -1426,9 +1426,9 @@ char *make_filter_cmd(char *cmd, char *itmp, char *otmp) } } xstrlcat(buf, " < ", len); - xstrlcat(buf, (const char *)itmp, len); + xstrlcat(buf, itmp, len); if (*p_shq == NUL) { - const char *const p = find_pipe((const char *)cmd); + const char *const p = find_pipe(cmd); if (p != NULL) { xstrlcat(buf, " ", len - 1); // Insert a space before the '|' for DOS xstrlcat(buf, p, len - 1); -- cgit From 2d78e656b715119ca11d131a1a932f22f1b4ad36 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 21:43:00 +0200 Subject: refactor: remove redundant casts --- src/nvim/ex_cmds.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index a67a01bcea..a1b43113a6 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -150,7 +150,7 @@ void do_ascii(const exarg_T *const eap) if (vim_isprintc_strict(c) && (c < ' ' || c > '~')) { char buf3[7]; transchar_nonprint(curbuf, buf3, c); - vim_snprintf(buf1, sizeof(buf1), " <%s>", (char *)buf3); + vim_snprintf(buf1, sizeof(buf1), " <%s>", buf3); } else { buf1[0] = NUL; } @@ -1361,12 +1361,12 @@ char *make_filter_cmd(char *cmd, char *itmp, char *otmp) { bool is_fish_shell = #if defined(UNIX) - strncmp((char *)invocation_path_tail(p_sh, NULL), "fish", 4) == 0; + strncmp(invocation_path_tail(p_sh, NULL), "fish", 4) == 0; #else false; #endif - bool is_pwsh = strncmp((char *)invocation_path_tail(p_sh, NULL), "pwsh", 4) == 0 - || strncmp((char *)invocation_path_tail(p_sh, NULL), "powershell", + bool is_pwsh = strncmp(invocation_path_tail(p_sh, NULL), "pwsh", 4) == 0 + || strncmp(invocation_path_tail(p_sh, NULL), "powershell", 10) == 0; size_t len = strlen(cmd) + 1; // At least enough space for cmd + NULL. @@ -4288,7 +4288,7 @@ bool do_sub_msg(bool count_only) "%" PRId64 " matches on %" PRId64 " lines", sub_nsubs) : NGETTEXT("%" PRId64 " substitution on %" PRId64 " lines", "%" PRId64 " substitutions on %" PRId64 " lines", sub_nsubs); - vim_snprintf_add((char *)msg_buf, sizeof(msg_buf), + vim_snprintf_add(msg_buf, sizeof(msg_buf), NGETTEXT(msg_single, msg_plural, sub_nlines), (int64_t)sub_nsubs, (int64_t)sub_nlines); if (msg(msg_buf)) { -- cgit From c0f10d3fe018990b68cfa47bd84693449100f449 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 18 Apr 2023 14:09:29 +0800 Subject: vim-patch:9.0.0783: ":!" doesn't do anything but does update the previous command Problem: ":!" doesn't do anything but does update the previous command. Solution: Do not have ":!" change the previous command. (Martin Tournoij, closes vim/vim#11372) https://github.com/vim/vim/commit/8107a2a8af80a53a61734b600539c5beb4782991 Co-authored-by: Bram Moolenaar --- src/nvim/ex_cmds.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index a1b43113a6..cc8c4aeca8 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1012,6 +1012,12 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } } while (trailarg != NULL); + // Don't do anything if there is no command as there isn't really anything + // useful in running "sh -c ''". Avoids changing "prevcmd". + if (strlen(newcmd) == 0) { + return; + } + xfree(prevcmd); prevcmd = newcmd; -- cgit From 5b77dde8dd281b1db1f503d9b270c3697f88bd65 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 18 Apr 2023 14:22:16 +0800 Subject: vim-patch:9.0.0785: memory leak with empty shell command Problem: Memory leak with empty shell command. Solution: Free the allocated memory when bailing out. https://github.com/vim/vim/commit/9652249a2d02318a28a63a7b5711f25652e8f969 Co-authored-by: Bram Moolenaar --- src/nvim/ex_cmds.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index cc8c4aeca8..015f651872 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1015,6 +1015,7 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out // Don't do anything if there is no command as there isn't really anything // useful in running "sh -c ''". Avoids changing "prevcmd". if (strlen(newcmd) == 0) { + xfree(newcmd); return; } -- cgit From 187ba3efce4acc197ce6cc9559a905eec97bacbe Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 18 Apr 2023 14:23:09 +0800 Subject: vim-patch:9.0.0815 https://github.com/vim/vim/commit/9c50eeb40117413bf59a9da904c8d0921ed0a6e6 Co-authored-by: Martin Tournoij --- src/nvim/ex_cmds.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 015f651872..f7447cda1b 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -988,6 +988,8 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } if (ins_prevcmd) { STRCAT(t, prevcmd); + } else { + xfree(t); } p = t + strlen(t); STRCAT(t, trailarg); @@ -1012,16 +1014,12 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } } while (trailarg != NULL); - // Don't do anything if there is no command as there isn't really anything - // useful in running "sh -c ''". Avoids changing "prevcmd". - if (strlen(newcmd) == 0) { - xfree(newcmd); - return; + // Don't clear "prevcmd" if there is no command to run. + if (strlen(newcmd) > 0) { + xfree(prevcmd); + prevcmd = newcmd; } - xfree(prevcmd); - prevcmd = newcmd; - if (bangredo) { // put cmd in redo buffer for ! command // If % or # appears in the command, it must have been escaped. // Reescape them, so that redoing them does not substitute them by the -- cgit From a1e0f6c07fc575dfac4cd4c0d8c395b8d3f1a4f4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 18 Apr 2023 14:28:00 +0800 Subject: vim-patch:9.0.0817 https://github.com/vim/vim/commit/fb0cf2357e0c85bbfd9f9178705ad8d77b6b3b4e Co-authored-by: Bram Moolenaar --- src/nvim/ex_cmds.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index f7447cda1b..db9cf94cba 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -988,8 +988,6 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } if (ins_prevcmd) { STRCAT(t, prevcmd); - } else { - xfree(t); } p = t + strlen(t); STRCAT(t, trailarg); -- cgit From 2a94dcf0c592464222c87f5606799ca51a0b9c07 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 18 Apr 2023 14:30:08 +0800 Subject: vim-patch:9.0.0820: memory leak with empty shell command Problem: Memory leak with empty shell command. Solution: Free the empty string. https://github.com/vim/vim/commit/03d6e6f42b0deeb02d52c8a48c14abe431370c1c Co-authored-by: Bram Moolenaar --- src/nvim/ex_cmds.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index db9cf94cba..55dbe17ad6 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1012,10 +1012,13 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } } while (trailarg != NULL); - // Don't clear "prevcmd" if there is no command to run. + // Only set "prevcmd" if there is a command to run, otherwise keep te one + // we have. if (strlen(newcmd) > 0) { xfree(prevcmd); prevcmd = newcmd; + } else { + free_newcmd = true; } if (bangredo) { // put cmd in redo buffer for ! command @@ -1031,6 +1034,9 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } // Add quotes around the command, for shells that need them. if (*p_shq != NUL) { + if (free_newcmd) { + xfree(newcmd); + } newcmd = xmalloc(strlen(prevcmd) + 2 * strlen(p_shq) + 1); STRCPY(newcmd, p_shq); STRCAT(newcmd, prevcmd); -- cgit From 9180c18c462a4945657899b732189da6f2ea2eaf Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 18 Apr 2023 14:31:40 +0800 Subject: vim-patch:9.0.0864: crash when using "!!" without a previous shell command Problem: Crash when using "!!" without a previous shell command. Solution: Check "prevcmd" is not NULL. (closes vim/vim#11487) https://github.com/vim/vim/commit/6600447c7b0a1be3a64d07a318bacdfaae0cac4b Co-authored-by: Bram Moolenaar --- src/nvim/ex_cmds.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 55dbe17ad6..b75ff45843 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -933,6 +933,17 @@ void free_prev_shellcmd(void) #endif +/// Check that "prevcmd" is not NULL. If it is NULL then give an error message +/// and return false. +static int prevcmd_is_set(void) +{ + if (prevcmd == NULL) { + emsg(_(e_noprev)); + return false; + } + return true; +} + /// Handle the ":!cmd" command. Also for ":r !cmd" and ":w !cmd" /// Bangs in the argument are replaced with the previously entered command. /// Remember the argument. @@ -974,8 +985,7 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out len += strlen(newcmd); } if (ins_prevcmd) { - if (prevcmd == NULL) { - emsg(_(e_noprev)); + if (!prevcmd_is_set()) { xfree(newcmd); return; } @@ -1022,6 +1032,10 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } if (bangredo) { // put cmd in redo buffer for ! command + if (!prevcmd_is_set()) { + goto theend; + } + // If % or # appears in the command, it must have been escaped. // Reescape them, so that redoing them does not substitute them by the // buffername. @@ -1059,6 +1073,8 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out do_filter(line1, line2, eap, newcmd, do_in, do_out); apply_autocmds(EVENT_SHELLFILTERPOST, NULL, NULL, false, curbuf); } + +theend: if (free_newcmd) { xfree(newcmd); } -- cgit From 7bf1a917b78ebc622b6691af9196b95b4a9d3142 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 19 Apr 2023 13:15:29 +0100 Subject: vim-patch:8.1.2094: the fileio.c file is too big Problem: The fileio.c file is too big. Solution: Move buf_write() to bufwrite.c. (Yegappan Lakshmanan, closes vim/vim#4990) https://github.com/vim/vim/commit/c079f0fed1c16495d726d616c5362edc04742a0d Co-authored-by: Yegappan Lakshmanan Co-authored-by: zeertzjq --- src/nvim/ex_cmds.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index b75ff45843..3c7e230ad3 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -23,6 +23,7 @@ #include "nvim/buffer.h" #include "nvim/buffer_defs.h" #include "nvim/buffer_updates.h" +#include "nvim/bufwrite.h" #include "nvim/change.h" #include "nvim/channel.h" #include "nvim/charset.h" -- cgit From 3b0df1780e2c8526bda5dead18ee7cc45925caba Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 26 Apr 2023 23:23:44 +0200 Subject: refactor: uncrustify Notable changes: replace all infinite loops to `while(true)` and remove `int` from `unsigned int`. --- src/nvim/ex_cmds.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 3c7e230ad3..7a77ffb4da 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1402,7 +1402,7 @@ char *make_filter_cmd(char *cmd, char *itmp, char *otmp) : 0; if (itmp != NULL) { - len += is_pwsh ? strlen(itmp) + sizeof("& { Get-Content " " | & " " }") - 1 + 6 // +6: #20530 + len += is_pwsh ? strlen(itmp) + sizeof("& { Get-Content " " | & " " }") - 1 + 6 // +6: #20530 : strlen(itmp) + sizeof(" { " " < " " } ") - 1; } if (otmp != NULL) { @@ -1427,7 +1427,7 @@ char *make_filter_cmd(char *cmd, char *itmp, char *otmp) // redirecting input and/or output. if (itmp != NULL || otmp != NULL) { char *fmt = is_fish_shell ? "begin; %s; end" - : "(%s)"; + : "(%s)"; vim_snprintf(buf, len, fmt, cmd); } else { xstrlcpy(buf, cmd, len); @@ -2782,7 +2782,7 @@ void ex_append(exarg_T *eap) State |= MODE_LANGMAP; } - for (;;) { + while (true) { msg_scroll = true; need_wait_return = false; if (curbuf->b_p_ai) { @@ -3581,7 +3581,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T // 3. substitute the string. // 4. if subflags.do_all is set, find next match // 5. break if there isn't another match in this line - for (;;) { + while (true) { SubResult current_match = { .start = { 0, 0 }, .end = { 0, 0 }, -- cgit From ff34c91194f9ab9d02808f2880029c38a4655eb5 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 17 Apr 2023 17:23:47 +0100 Subject: vim-patch:9.0.1330: handling new value of an option has a long "else if" chain Problem: Handling new value of an option has a long "else if" chain. Solution: Use a function pointer. (Yegappan Lakshmanan, closes vim/vim#12015) https://github.com/vim/vim/commit/af93691b53f38784efce0b93fe7644c44a7e382e --- src/nvim/ex_cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 7a77ffb4da..f276e8ae24 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -2640,7 +2640,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum // If the window options were changed may need to set the spell language. // Can only do this after the buffer has been properly setup. if (did_get_winopts && curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) { - (void)did_set_spelllang(curwin); + (void)parse_spelllang(curwin); } if (command == NULL) { -- cgit From c426f7a6228cb82af0f75ac4f2421543408ff091 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Thu, 27 Apr 2023 00:03:46 +0200 Subject: vim-patch:9.0.0751: 'scrolloff' does not work well with 'smoothscroll' Problem: 'scrolloff' does not work well with 'smoothscroll'. Solution: Make positioning the cursor a bit better. Rename functions. https://github.com/vim/vim/commit/c9121f798f49fa71e814912cb186d89c164090c3 Co-authored-by: Bram Moolenaar --- src/nvim/ex_cmds.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index f276e8ae24..2c31f742c3 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -346,10 +346,8 @@ static int linelen(int *has_tab) last > first && ascii_iswhite(last[-1]); last--) {} char save = *last; *last = NUL; - // Get line length. - len = linetabsize(line); - // Check for embedded TAB. - if (has_tab != NULL) { + len = linetabsize_str(line); // Get line length. + if (has_tab != NULL) { // Check for embedded TAB. *has_tab = vim_strchr(first, TAB) != NULL; } *last = save; -- cgit From 88cfb49bee3c9102082c7010acb92244e4ad1348 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 07:14:39 +0800 Subject: vim-patch:8.2.4890: inconsistent capitalization in error messages Problem: Inconsistent capitalization in error messages. Solution: Make capitalization consistent. (Doug Kearns) https://github.com/vim/vim/commit/cf030578b26460643dca4a40e7f2e3bc19c749aa Co-authored-by: Bram Moolenaar --- src/nvim/ex_cmds.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 2c31f742c3..dbfd1088d2 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -126,6 +126,9 @@ typedef struct { # include "ex_cmds.c.generated.h" #endif +static const char e_non_numeric_argument_to_z[] + = N_("E144: Non-numeric argument to :z"); + /// ":ascii" and "ga" implementation void do_ascii(const exarg_T *const eap) { @@ -2952,7 +2955,7 @@ void ex_z(exarg_T *eap) if (*x != 0) { if (!ascii_isdigit(*x)) { - emsg(_("E144: non-numeric argument to :z")); + emsg(_(e_non_numeric_argument_to_z)); return; } bigness = atol(x); -- cgit From 9d306ac6b79c13b5f42ea4e22c6f8ccc628f6a6a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 11 May 2023 08:09:13 +0800 Subject: vim-patch:9.0.1538: :wqall does not trigger ExitPre (#23574) Problem: :wqall does not trigger ExitPre. (Bart Libert) Solution: Move preparations for :qall to a common function. (closes vim/vim#12374) https://github.com/vim/vim/commit/411da64e77ef9d8edd1a5aa80fa5b9a4b159c93d Co-authored-by: Bram Moolenaar --- src/nvim/ex_cmds.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index dbfd1088d2..9a8dc9899c 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1926,6 +1926,9 @@ void do_wqall(exarg_T *eap) int save_forceit = eap->forceit; if (eap->cmdidx == CMD_xall || eap->cmdidx == CMD_wqall) { + if (before_quit_all(eap) == FAIL) { + return; + } exiting = true; } -- cgit From 01ea42c32afe8d235d2110a5fcf12a353a7d2a71 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 22 May 2023 09:24:36 +0100 Subject: refactor(vim.secure): move to lua/secure.c --- src/nvim/ex_cmds.c | 27 --------------------------- 1 file changed, 27 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 9a8dc9899c..1d8c3c0cf4 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -54,7 +54,6 @@ #include "nvim/highlight_group.h" #include "nvim/indent.h" #include "nvim/input.h" -#include "nvim/lua/executor.h" #include "nvim/macros.h" #include "nvim/main.h" #include "nvim/mark.h" @@ -4804,29 +4803,3 @@ void ex_oldfiles(exarg_T *eap) } } } - -void ex_trust(exarg_T *eap) -{ - const char *const p = skiptowhite(eap->arg); - char *arg1 = xmemdupz(eap->arg, (size_t)(p - eap->arg)); - const char *action = "allow"; - const char *path = skipwhite(p); - - if (strcmp(arg1, "++deny") == 0) { - action = "deny"; - } else if (strcmp(arg1, "++remove") == 0) { - action = "remove"; - } else if (*arg1 != '\0') { - semsg(e_invarg2, arg1); - goto theend; - } - - if (path[0] == '\0') { - path = NULL; - } - - nlua_trust(action, path); - -theend: - xfree(arg1); -} -- cgit From 9dd48f7832f4656af4a2579368641268bb6399e7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 29 May 2023 08:44:52 +0800 Subject: fix(substitute): properly check if preview is needed (#23809) --- src/nvim/ex_cmds.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 1d8c3c0cf4..40afb3250c 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3280,9 +3280,11 @@ static int check_regexp_delim(int c) /// /// The usual escapes are supported as described in the regexp docs. /// -/// @param do_buf_event If `true`, send buffer updates. +/// @param cmdpreview_ns The namespace to show 'inccommand' preview highlights. +/// If <= 0, preview shouldn't be shown. /// @return 0, 1 or 2. See show_cmdpreview() for more information on what the return value means. -static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T cmdpreview_bufnr) +static int do_sub(exarg_T *eap, const proftime_T timeout, const long cmdpreview_ns, + const handle_T cmdpreview_bufnr) { #define ADJUST_SUB_FIRSTLNUM() \ do { \ @@ -3400,7 +3402,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T MB_PTR_ADV(cmd); } - if (!eap->skip && !cmdpreview) { + if (!eap->skip && cmdpreview_ns <= 0) { sub_set_replacement((SubReplacementString) { .sub = xstrdup(sub), .timestamp = os_time(), @@ -3420,7 +3422,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T endcolumn = (curwin->w_curswant == MAXCOL); } - if (sub != NULL && sub_joining_lines(eap, pat, sub, cmd, !cmdpreview)) { + if (sub != NULL && sub_joining_lines(eap, pat, sub, cmd, cmdpreview_ns <= 0)) { return 0; } @@ -3465,7 +3467,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T } if (search_regcomp(pat, NULL, RE_SUBST, which_pat, - (cmdpreview ? 0 : SEARCH_HIS), ®match) == FAIL) { + (cmdpreview_ns > 0 ? 0 : SEARCH_HIS), ®match) == FAIL) { if (subflags.do_error) { emsg(_(e_invcmd)); } @@ -3494,7 +3496,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T sub = xstrdup(sub); sub_copy = sub; } else { - char *newsub = regtilde(sub, magic_isset(), cmdpreview); + char *newsub = regtilde(sub, magic_isset(), cmdpreview_ns > 0); if (newsub != sub) { // newsub was allocated, free it later. sub_copy = newsub; @@ -3508,7 +3510,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T for (linenr_T lnum = eap->line1; lnum <= line2 && !got_quit && !aborting() - && (!cmdpreview || preview_lines.lines_needed <= (linenr_T)p_cwh + && (cmdpreview_ns <= 0 || preview_lines.lines_needed <= (linenr_T)p_cwh || lnum <= curwin->w_botline); lnum++) { long nmatch = vim_regexec_multi(®match, curwin, curbuf, lnum, @@ -3669,7 +3671,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T } } - if (subflags.do_ask && !cmdpreview) { + if (subflags.do_ask && cmdpreview_ns <= 0) { int typed = 0; // change State to MODE_CONFIRM, so that the mouse works @@ -3882,7 +3884,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T // Save the line numbers for the preview buffer // NOTE: If the pattern matches a final newline, the next line will // be shown also, but should not be highlighted. Intentional for now. - if (cmdpreview && !has_second_delim) { + if (cmdpreview_ns > 0 && !has_second_delim) { current_match.start.col = regmatch.startpos[0].col; if (current_match.end.lnum == 0) { current_match.end.lnum = sub_firstlnum + (linenr_T)nmatch - 1; @@ -3897,7 +3899,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T // 3. Substitute the string. During 'inccommand' preview only do this if // there is a replace pattern. - if (!cmdpreview || has_second_delim) { + if (cmdpreview_ns <= 0 || has_second_delim) { long lnum_start = lnum; // save the start lnum int save_ma = curbuf->b_p_ma; int save_sandbox = sandbox; @@ -4147,7 +4149,7 @@ skip: #define PUSH_PREVIEW_LINES() \ do { \ - if (cmdpreview) { \ + if (cmdpreview_ns > 0) { \ linenr_T match_lines = current_match.end.lnum \ - current_match.start.lnum +1; \ if (preview_lines.subresults.size > 0) { \ @@ -4230,7 +4232,7 @@ skip: beginline(BL_WHITE | BL_FIX); } } - if (!cmdpreview && !do_sub_msg(subflags.do_count) && subflags.do_ask && p_ch > 0) { + if (cmdpreview_ns <= 0 && !do_sub_msg(subflags.do_count) && subflags.do_ask && p_ch > 0) { msg(""); } } else { @@ -4269,7 +4271,7 @@ skip: int retv = 0; // Show 'inccommand' preview if there are matched lines. - if (cmdpreview && !aborting()) { + if (cmdpreview_ns > 0 && !aborting()) { if (got_quit || profile_passed_limit(timeout)) { // Too slow, disable. set_string_option_direct("icm", -1, "", OPT_FREE, SID_NONE); } else if (*p_icm != NUL && pat != NULL) { -- cgit From aa362a2af8ce353d7082834a54bcc124ebd2a026 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 29 Jun 2023 15:48:42 +0800 Subject: refactor: remove some casts to char * (#24200) --- src/nvim/ex_cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 40afb3250c..591f8febdc 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -389,7 +389,7 @@ typedef struct { static int string_compare(const void *s1, const void *s2) FUNC_ATTR_NONNULL_ALL { if (sort_lc) { - return strcoll((char *)s1, (char *)s2); + return strcoll((const char *)s1, (const char *)s2); } return sort_ic ? STRICMP(s1, s2) : strcmp(s1, s2); } -- cgit From fcf3519c65a2d6736de437f686e788684a6c8564 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 17 Apr 2023 22:18:58 +0200 Subject: refactor: remove long long is 32-bits even on 64-bit windows which makes the type suboptimal for a codebase meant to be cross-platform. --- src/nvim/ex_cmds.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 591f8febdc..68f9aa87ee 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -462,7 +462,7 @@ void ex_sort(exarg_T *eap) char *s2; char c; // temporary character storage bool unique = false; - long deleted; + linenr_T deleted; colnr_T start_col; colnr_T end_col; int sort_what = 0; @@ -689,13 +689,12 @@ void ex_sort(exarg_T *eap) } // Adjust marks for deleted (or added) lines and prepare for displaying. - deleted = (long)count - (lnum - eap->line2); + deleted = (linenr_T)count - (lnum - eap->line2); if (deleted > 0) { - mark_adjust(eap->line2 - (linenr_T)deleted, eap->line2, (long)MAXLNUM, (linenr_T)(-deleted), - kExtmarkNOOP); + mark_adjust(eap->line2 - deleted, eap->line2, (long)MAXLNUM, -deleted, kExtmarkNOOP); msgmore(-deleted); } else if (deleted < 0) { - mark_adjust(eap->line2, MAXLNUM, (linenr_T)(-deleted), 0L, kExtmarkNOOP); + mark_adjust(eap->line2, MAXLNUM, -deleted, 0L, kExtmarkNOOP); } if (change_occurred || deleted != 0) { @@ -703,7 +702,7 @@ void ex_sort(exarg_T *eap) (int)count, 0, old_count, lnum - eap->line2, 0, new_count, kExtmarkUndo); - changed_lines(eap->line1, 0, eap->line2 + 1, (linenr_T)(-deleted), true); + changed_lines(eap->line1, 0, eap->line2 + 1, -deleted, true); } curwin->w_cursor.lnum = eap->line1; @@ -3900,7 +3899,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const long cmdpreview_ // 3. Substitute the string. During 'inccommand' preview only do this if // there is a replace pattern. if (cmdpreview_ns <= 0 || has_second_delim) { - long lnum_start = lnum; // save the start lnum + linenr_T lnum_start = lnum; // save the start lnum int save_ma = curbuf->b_p_ma; int save_sandbox = sandbox; if (subflags.do_count) { @@ -4038,7 +4037,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const long cmdpreview_ } extmark_splice(curbuf, (int)lnum_start - 1, start_col, end.lnum - start.lnum, matchcols, replaced_bytes, - lnum - (linenr_T)lnum_start, subcols, sublen - 1, kExtmarkUndo); + lnum - lnum_start, subcols, sublen - 1, kExtmarkUndo); } // 4. If subflags.do_all is set, find next match. -- cgit From cefd774fac76b91f5368833555818c80c992c3b1 Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 24 Aug 2023 15:14:23 +0200 Subject: refactor(memline): distinguish mutating uses of ml_get_buf() ml_get_buf() takes a third parameters to indicate whether the caller wants to mutate the memline data in place. However the vast majority of the call sites is using this function just to specify a buffer but without any mutation. This makes it harder to grep for the places which actually perform mutation. Solution: Remove the bool param from ml_get_buf(). it now works like ml_get() except for a non-current buffer. Add a new ml_get_buf_mut() function for the mutating use-case, which can be grepped along with the other ml_replace() etc functions which can modify the memline. --- src/nvim/ex_cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 68f9aa87ee..b4d07cc78a 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -4644,7 +4644,7 @@ static int show_sub(exarg_T *eap, pos_T old_cusr, PreviewLines *preview_lines, i if (next_linenr == orig_buf->b_ml.ml_line_count + 1) { line = ""; } else { - line = ml_get_buf(orig_buf, next_linenr, false); + line = ml_get_buf(orig_buf, next_linenr); line_size = strlen(line) + (size_t)col_width + 1; // Reallocate if line not long enough -- cgit From 008154954791001efcc46c28146e21403f3a698b Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 21 Aug 2023 14:52:17 +0200 Subject: refactor(change): do API changes to buffer without curbuf switch Most of the messy things when changing a non-current buffer is not about the buffer, it is about windows. In particular, it is about `curwin`. When editing a non-current buffer which is displayed in some other window in the current tabpage, one such window will be "borrowed" as the curwin. But this means if two or more non-current windows displayed the buffers, one of them will be treated differenty. this is not desirable. In particular, with nvim_buf_set_text, cursor _column_ position was only corrected for one single window. Two new tests are added: the test with just one non-current window passes, but the one with two didn't. Two corresponding such tests were also added for nvim_buf_set_lines. This already worked correctly on master, but make sure this is well-tested for future refactors. Also, nvim_create_buf no longer invokes autocmds just because you happened to use `scratch=true`. No option value was changed, therefore OptionSet must not be fired. --- src/nvim/ex_cmds.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index b4d07cc78a..494ebce370 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -321,7 +321,7 @@ void ex_align(exarg_T *eap) } (void)set_indent(new_indent, 0); // set indent } - changed_lines(eap->line1, 0, eap->line2 + 1, 0L, true); + changed_lines(curbuf, eap->line1, 0, eap->line2 + 1, 0L, true); curwin->w_cursor = save_curpos; beginline(BL_WHITE | BL_FIX); } @@ -702,7 +702,7 @@ void ex_sort(exarg_T *eap) (int)count, 0, old_count, lnum - eap->line2, 0, new_count, kExtmarkUndo); - changed_lines(eap->line1, 0, eap->line2 + 1, -deleted, true); + changed_lines(curbuf, eap->line1, 0, eap->line2 + 1, -deleted, true); } curwin->w_cursor.lnum = eap->line1; @@ -784,7 +784,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) mark_adjust_nofold(line1, line2, last_line - line2, 0L, kExtmarkNOOP); disable_fold_update++; - changed_lines(last_line - num_lines + 1, 0, last_line + 1, num_lines, false); + changed_lines(curbuf, last_line - num_lines + 1, 0, last_line + 1, num_lines, false); disable_fold_update--; int line_off = 0; @@ -821,7 +821,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) -(last_line - dest - extra), 0L, kExtmarkNOOP); disable_fold_update++; - changed_lines(last_line - num_lines + 1, 0, last_line + 1, -extra, false); + changed_lines(curbuf, last_line - num_lines + 1, 0, last_line + 1, -extra, false); disable_fold_update--; // send update regarding the new lines that were added @@ -859,9 +859,9 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) if (dest > last_line + 1) { dest = last_line + 1; } - changed_lines(line1, 0, dest, 0L, false); + changed_lines(curbuf, line1, 0, dest, 0L, false); } else { - changed_lines(dest + 1, 0, line1 + num_lines, 0L, false); + changed_lines(curbuf, dest + 1, 0, line1 + num_lines, 0L, false); } // send nvim_buf_lines_event regarding lines that were deleted @@ -1124,7 +1124,7 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b curwin->w_cursor.lnum = line1; curwin->w_cursor.col = 0; changed_line_abv_curs(); - invalidate_botline(); + invalidate_botline(curwin); // When using temp files: // 1. * Form temp file names @@ -2088,7 +2088,7 @@ int getfile(int fnum, char *ffname_arg, char *sfname_arg, int setpm, linenr_T ln if (lnum != 0) { curwin->w_cursor.lnum = lnum; } - check_cursor_lnum(); + check_cursor_lnum(curwin); beginline(BL_SOL | BL_FIX); retval = GETFILE_SAME_FILE; // it's in the same file } else if (do_ecmd(fnum, ffname, sfname, NULL, lnum, @@ -2652,7 +2652,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum check_cursor(); } else if (newlnum > 0) { // line number from caller or old position curwin->w_cursor.lnum = newlnum; - check_cursor_lnum(); + check_cursor_lnum(curwin); if (solcol >= 0 && !p_sol) { // 'sol' is off: Use last known column. curwin->w_cursor.col = solcol; @@ -2883,7 +2883,7 @@ void ex_append(exarg_T *eap) curbuf->b_op_start.col = curbuf->b_op_end.col = 0; } curwin->w_cursor.lnum = lnum; - check_cursor_lnum(); + check_cursor_lnum(curwin); beginline(BL_SOL | BL_FIX); need_wait_return = false; // don't use wait_return() now @@ -2913,7 +2913,7 @@ void ex_change(exarg_T *eap) } // make sure the cursor is not beyond the end of the file now - check_cursor_lnum(); + check_cursor_lnum(curwin); deleted_lines_mark(eap->line1, (eap->line2 - lnum)); // ":append" on the line above the deleted lines. @@ -4200,7 +4200,7 @@ skip: // the line number before the change (same as adding the number of // deleted lines). i = curbuf->b_ml.ml_line_count - old_line_count; - changed_lines(first_line, 0, last_line - (linenr_T)i, (linenr_T)i, false); + changed_lines(curbuf, first_line, 0, last_line - (linenr_T)i, (linenr_T)i, false); int64_t num_added = last_line - first_line; int64_t num_removed = num_added - i; @@ -4611,9 +4611,6 @@ static int show_sub(exarg_T *eap, pos_T old_cusr, PreviewLines *preview_lines, i linenr_T linenr_origbuf = 0; // last line added to original buffer linenr_T next_linenr = 0; // next line to show for the match - // Temporarily switch to preview buffer - aco_save_T aco; - for (size_t matchidx = 0; matchidx < lines.subresults.size; matchidx++) { SubResult match = lines.subresults.items[matchidx]; @@ -4621,6 +4618,9 @@ static int show_sub(exarg_T *eap, pos_T old_cusr, PreviewLines *preview_lines, i lpos_T p_start = { 0, match.start.col }; // match starts here in preview lpos_T p_end = { 0, match.end.col }; // ... and ends here + // You Might Gonna Need It + buf_ensure_loaded(cmdpreview_buf); + if (match.pre_match == 0) { next_linenr = match.start.lnum; } else { @@ -4656,14 +4656,11 @@ static int show_sub(exarg_T *eap, pos_T old_cusr, PreviewLines *preview_lines, i // Put "|lnum| line" into `str` and append it to the preview buffer. snprintf(str, line_size, "|%*" PRIdLINENR "| %s", col_width - 3, next_linenr, line); - // Temporarily switch to preview buffer - aucmd_prepbuf(&aco, cmdpreview_buf); if (linenr_preview == 0) { - ml_replace(1, str, true); + ml_replace_buf(cmdpreview_buf, 1, str, true); } else { - ml_append(linenr_preview, str, (colnr_T)line_size, false); + ml_append_buf(cmdpreview_buf, linenr_preview, str, (colnr_T)line_size, false); } - aucmd_restbuf(&aco); linenr_preview += 1; } linenr_origbuf = match.end.lnum; -- cgit From 087ef5299789123aa40e44937ef9bc31d49fd085 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 3 Sep 2023 11:15:43 +0800 Subject: vim-patch:9.0.1840: [security] use-after-free in do_ecmd (#24993) Problem: use-after-free in do_ecmd Solution: Verify oldwin pointer after reset_VIsual() https://github.com/vim/vim/commit/e1dc9a627536304bc4f738c21e909ad9fcf3974c N/A patches for version.c: vim-patch:9.0.1841: style: trailing whitespace in ex_cmds.c Co-authored-by: Christian Brabandt --- src/nvim/ex_cmds.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 494ebce370..82ebf1871a 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -2230,8 +2230,16 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum // End Visual mode before switching to another buffer, so the text can be // copied into the GUI selection buffer. + // Careful: may trigger ModeChanged() autocommand + + // Should we block autocommands here? reset_VIsual(); + // autocommands freed window :( + if (oldwin != NULL && !win_valid(oldwin)) { + oldwin = NULL; + } + if ((command != NULL || newlnum > (linenr_T)0) && *get_vim_var_str(VV_SWAPCOMMAND) == NUL) { // Set v:swapcommand for the SwapExists autocommands. -- cgit From 0e11bf0e1af5b3422db49222ab739a64d233b353 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 3 Sep 2023 12:32:58 +0800 Subject: perf(substitute): don't reallocate new_start every time (#24997) --- src/nvim/ex_cmds.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 82ebf1871a..f017550dd4 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3177,21 +3177,21 @@ static bool sub_joining_lines(exarg_T *eap, char *pat, const char *sub, const ch /// Slightly more memory that is strictly necessary is allocated to reduce the /// frequency of memory (re)allocation. /// -/// @param[in,out] new_start pointer to the memory for the replacement text -/// @param[in] needed_len amount of memory needed +/// @param[in,out] new_start pointer to the memory for the replacement text +/// @param[in,out] new_start_len pointer to length of new_start +/// @param[in] needed_len amount of memory needed /// /// @returns pointer to the end of the allocated memory -static char *sub_grow_buf(char **new_start, int needed_len) - FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_NONNULL_RET +static char *sub_grow_buf(char **new_start, int *new_start_len, int needed_len) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET { - int new_start_len = 0; char *new_end; if (*new_start == NULL) { // Get some space for a temporary buffer to do the // substitution into (and some extra space to avoid // too many calls to xmalloc()/free()). - new_start_len = needed_len + 50; - *new_start = xmalloc((size_t)new_start_len); + *new_start_len = needed_len + 50; + *new_start = xmalloc((size_t)(*new_start_len)); **new_start = NUL; new_end = *new_start; } else { @@ -3200,9 +3200,9 @@ static char *sub_grow_buf(char **new_start, int needed_len) // extra to avoid too many calls to xmalloc()/free()). size_t len = strlen(*new_start); needed_len += (int)len; - if (needed_len > new_start_len) { - new_start_len = needed_len + 50; - *new_start = xrealloc(*new_start, (size_t)new_start_len); + if (needed_len > *new_start_len) { + *new_start_len = needed_len + 50; + *new_start = xrealloc(*new_start, (size_t)(*new_start_len)); } new_end = *new_start + len; } @@ -3527,6 +3527,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const long cmdpreview_ colnr_T matchcol; colnr_T prev_matchcol = MAXCOL; char *new_end, *new_start = NULL; + int new_start_len = 0; char *p1; bool did_sub = false; int lastone; @@ -3572,7 +3573,8 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const long cmdpreview_ // accordingly. // // The new text is built up in new_start[]. It has some extra - // room to avoid using xmalloc()/free() too often. + // room to avoid using xmalloc()/free() too often. new_start_len is + // the length of the allocated memory at new_start. // // Make a copy of the old line, so it won't be taken away when // updating the screen or handling a multi-line match. The "old_" @@ -3952,7 +3954,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const long cmdpreview_ nmatch_tl += nmatch - 1; } size_t copy_len = (size_t)(regmatch.startpos[0].col - copycol); - new_end = sub_grow_buf(&new_start, + new_end = sub_grow_buf(&new_start, &new_start_len, (colnr_T)strlen(p1) - regmatch.endpos[0].col + (colnr_T)copy_len + sublen + 1); -- cgit From bebdf1dab345471222f6755c574d04596fea92fd Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 3 Sep 2023 13:47:55 +0800 Subject: vim-patch:9.0.1848: [security] buffer-overflow in vim_regsub_both() (#25001) Problem: buffer-overflow in vim_regsub_both() Solution: Check remaining space https://github.com/vim/vim/commit/ced2c7394aafdc90fb7845e09b3a3fee23d48cb1 The change to do_sub() looks confusing. Maybe it's an overflow check? Then the crash may not be applicable to Nvim because of different casts. The test also looks confusing. It seems to source itself recursively. Also don't call strlen() twice on evaluation result. N/A patches for version.c: vim-patch:9.0.1849: CI error on different signedness in ex_cmds.c vim-patch:9.0.1853: CI error on different signedness in regexp.c Co-authored-by: Christian Brabandt --- src/nvim/ex_cmds.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index f017550dd4..a0618ce7d7 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3953,15 +3953,19 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const long cmdpreview_ p1 = ml_get(sub_firstlnum + (linenr_T)nmatch - 1); nmatch_tl += nmatch - 1; } - size_t copy_len = (size_t)(regmatch.startpos[0].col - copycol); + int copy_len = regmatch.startpos[0].col - copycol; new_end = sub_grow_buf(&new_start, &new_start_len, (colnr_T)strlen(p1) - regmatch.endpos[0].col - + (colnr_T)copy_len + sublen + 1); + + copy_len + sublen + 1); // copy the text up to the part that matched - memmove(new_end, sub_firstline + copycol, copy_len); + memmove(new_end, sub_firstline + copycol, (size_t)copy_len); new_end += copy_len; + if (new_start_len - copy_len < sublen) { + sublen = new_start_len - copy_len - 1; + } + // Finally, at this point we can know where the match actually will // start in the new text int start_col = (int)(new_end - new_start); -- cgit From bc09fc04b8ef216bafa34792c3486a750e5c8bb3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 9 Sep 2023 17:51:02 +0800 Subject: vim-patch:9.0.1877: missing test for patch 9.0.1873 Problem: missing test for patch 9.0.1873 Solution: add a test trying to exchange windows Add a test, making sure that switching windows is not allowed when textlock is active, e.g. when running `:s//\=func()/` https://github.com/vim/vim/commit/18d2709aa12ffa3f6ae1a13059990558c5f8e406 Co-authored-by: Christian Brabandt --- src/nvim/ex_cmds.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index a0618ce7d7..4f6b8f2c8f 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3888,6 +3888,10 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const long cmdpreview_ nmatch = curbuf->b_ml.ml_line_count - sub_firstlnum + 1; current_match.end.lnum = sub_firstlnum + (linenr_T)nmatch; skip_match = true; + // safety check + if (nmatch < 0) { + goto skip; + } } // Save the line numbers for the preview buffer -- cgit From 68d425ac92599089047d98f1c533981ea917fed1 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 25 Sep 2023 12:26:01 +0200 Subject: refactor: remove 'shortmess' save/restore panic for ex commands This was only used to avoid the effect of SHM_OVERALL. This can easily be handled in isolation, instead of clearing out all of 'shortmess' which has unwanted side effects and mystifies what really is going on. --- src/nvim/ex_cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 4f6b8f2c8f..dc7136196e 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -2689,7 +2689,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum // Obey the 'O' flag in 'cpoptions': overwrite any previous file // message. - if (shortmess(SHM_OVERALL) && !exiting && p_verbose == 0) { + if (shortmess(SHM_OVERALL) && !msg_listdo_overwrite && !exiting && p_verbose == 0) { msg_scroll = false; } if (!msg_scroll) { // wait a bit when overwriting an error msg -- cgit From f91cd31d7d9d70006e0000592637d5d997eab52c Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 27 Sep 2023 21:46:39 +0200 Subject: refactor(messages): fold msg_outtrans_attr into msg_outtrans problem: there are too many different functions in message.c solution: fold some of the functions into themselves --- src/nvim/ex_cmds.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index dc7136196e..6a5e8a8d38 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1062,7 +1062,7 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out msg_start(); msg_putchar(':'); msg_putchar('!'); - msg_outtrans(newcmd); + msg_outtrans(newcmd, 0); msg_clr_eos(); ui_cursor_goto(msg_row, msg_col); @@ -4790,7 +4790,7 @@ void ex_oldfiles(exarg_T *eap) if (!message_filtered(fname)) { msg_outnum(nr); msg_puts(": "); - msg_outtrans(tv_get_string(TV_LIST_ITEM_TV(li))); + msg_outtrans(tv_get_string(TV_LIST_ITEM_TV(li)), 0); msg_clr_eos(); msg_putchar('\n'); os_breakcheck(); -- cgit From b85f1dafc7c0a19704135617454f1c66f41202c1 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 27 Sep 2023 22:21:17 +0200 Subject: refactor(messages): fold msg_attr into msg problem: there are too many different functions in message.c solution: fold some of the functions into themselves --- src/nvim/ex_cmds.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 6a5e8a8d38..9eea29b3a2 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -135,7 +135,7 @@ void do_ascii(const exarg_T *const eap) int cc[MAX_MCO]; int c = utfc_ptr2char(get_cursor_pos_ptr(), cc); if (c == NUL) { - msg("NUL"); + msg("NUL", 0); return; } @@ -233,7 +233,7 @@ void do_ascii(const exarg_T *const eap) xstrlcpy(IObuff + iobuff_len, " ...", sizeof(IObuff) - iobuff_len); } - msg(IObuff); + msg(IObuff, 0); } /// ":left", ":center" and ":right": align text. @@ -1274,7 +1274,7 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b if (do_in) { vim_snprintf(msg_buf, sizeof(msg_buf), _("%" PRId64 " lines filtered"), (int64_t)linecount); - if (msg(msg_buf) && !msg_scroll) { + if (msg(msg_buf, 0) && !msg_scroll) { // save message to display it after redraw set_keep_msg(msg_buf, 0); } @@ -4250,7 +4250,7 @@ skip: } } if (cmdpreview_ns <= 0 && !do_sub_msg(subflags.do_count) && subflags.do_ask && p_ch > 0) { - msg(""); + msg("", 0); } } else { global_need_beginline = true; @@ -4265,7 +4265,7 @@ skip: } else if (got_match) { // did find something but nothing substituted if (p_ch > 0) { - msg(""); + msg("", 0); } } else if (subflags.do_error) { // nothing found @@ -4339,7 +4339,7 @@ bool do_sub_msg(bool count_only) vim_snprintf_add(msg_buf, sizeof(msg_buf), NGETTEXT(msg_single, msg_plural, sub_nlines), (int64_t)sub_nsubs, (int64_t)sub_nlines); - if (msg(msg_buf)) { + if (msg(msg_buf, 0)) { // save message to display it after redraw set_keep_msg(msg_buf, 0); } @@ -4468,7 +4468,7 @@ void ex_global(exarg_T *eap) // pass 2: execute the command for each line that has been marked if (got_int) { - msg(_(e_interr)); + msg(_(e_interr), 0); } else if (ndone == 0) { if (type == 'v') { smsg(_("Pattern found in every line: %s"), used_pat); @@ -4775,7 +4775,7 @@ void ex_oldfiles(exarg_T *eap) long nr = 0; if (l == NULL) { - msg(_("No old files")); + msg(_("No old files"), 0); return; } -- cgit From af7d317f3ff31d5ac5d8724b5057a422e1451b54 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 26 Sep 2023 22:36:08 +0200 Subject: refactor: remove long long is 32-bits even on 64-bit windows which makes the type suboptimal for a codebase meant to be cross-platform. --- src/nvim/ex_cmds.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 9eea29b3a2..bc82226d95 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -2148,7 +2148,6 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum bufref_T old_curbuf; char *free_fname = NULL; int retval = FAIL; - long n; pos_T orig_pos; linenr_T topline = 0; int newcol = -1; @@ -2158,7 +2157,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum bool did_get_winopts = false; int readfile_flags = 0; bool did_inc_redrawing_disabled = false; - long *so_ptr = curwin->w_p_so >= 0 ? &curwin->w_p_so : &p_so; + OptInt *so_ptr = curwin->w_p_so >= 0 ? &curwin->w_p_so : &p_so; if (eap != NULL) { command = eap->do_ecmd_cmd; @@ -2719,7 +2718,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum RedrawingDisabled--; did_inc_redrawing_disabled = false; if (!skip_redraw) { - n = *so_ptr; + OptInt n = *so_ptr; if (topline == 0 && command == NULL) { *so_ptr = 999; // force cursor to be vertically centered in the window } -- cgit From bc13bc154aa574e0bb58a50f2e0ca4570efa57c3 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 29 Sep 2023 16:10:54 +0200 Subject: refactor(message): smsg_attr -> smsg --- src/nvim/ex_cmds.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index bc82226d95..e9d8947bd3 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -836,8 +836,8 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) ml_delete(line1 + extra, true); } if (!global_busy && num_lines > p_report) { - smsg(NGETTEXT("%" PRId64 " line moved", - "%" PRId64 " lines moved", num_lines), + smsg(0, NGETTEXT("%" PRId64 " line moved", + "%" PRId64 " lines moved", num_lines), (int64_t)num_lines); } @@ -3800,8 +3800,8 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const long cmdpreview_ // needed msg_no_more = true; msg_ext_set_kind("confirm_sub"); - smsg_attr(HL_ATTR(HLF_R), // Same highlight as wait_return(). - _("replace with %s (y/n/a/q/l/^E/^Y)?"), sub); + // Same highlight as wait_return(). + smsg(HL_ATTR(HLF_R), _("replace with %s (y/n/a/q/l/^E/^Y)?"), sub); msg_no_more = false; msg_scroll = (int)i; if (!ui_has(kUIMessages)) { @@ -4470,9 +4470,9 @@ void ex_global(exarg_T *eap) msg(_(e_interr), 0); } else if (ndone == 0) { if (type == 'v') { - smsg(_("Pattern found in every line: %s"), used_pat); + smsg(0, _("Pattern found in every line: %s"), used_pat); } else { - smsg(_("Pattern not found: %s"), used_pat); + smsg(0, _("Pattern not found: %s"), used_pat); } } else { global_exe(cmd); -- cgit From dc6d0d2daf69e2fdadda81feb97906dbc962a239 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 14:41:34 +0800 Subject: refactor: reorganize option header files (#25437) - Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other --- src/nvim/ex_cmds.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index e9d8947bd3..127397d9fa 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -66,6 +66,7 @@ #include "nvim/normal.h" #include "nvim/ops.h" #include "nvim/option.h" +#include "nvim/option_vars.h" #include "nvim/optionstr.h" #include "nvim/os/fs_defs.h" #include "nvim/os/input.h" -- cgit From 09a17f91d0d362c6e58bfdbe3ccdeacffb0b44b9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 2 Oct 2023 10:45:33 +0800 Subject: refactor: move cmdline completion types to cmdexpand_defs.h (#25465) --- src/nvim/ex_cmds.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 127397d9fa..eb1ce5457e 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -27,6 +27,7 @@ #include "nvim/change.h" #include "nvim/channel.h" #include "nvim/charset.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/cmdhist.h" #include "nvim/cursor.h" #include "nvim/decoration.h" -- cgit From fd791db0ecebf5d5bf8922ba519f8dd4eef3c5e6 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 3 Oct 2023 00:19:30 +0200 Subject: fix: fix ASAN errors on clang 17 (#25469) --- src/nvim/ex_cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index eb1ce5457e..e866ed46a4 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -131,7 +131,7 @@ static const char e_non_numeric_argument_to_z[] = N_("E144: Non-numeric argument to :z"); /// ":ascii" and "ga" implementation -void do_ascii(const exarg_T *const eap) +void do_ascii(exarg_T *eap) { char *dig; int cc[MAX_MCO]; -- cgit From e72b546354cd90bf0cd8ee6dd045538d713009ad Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/ex_cmds.c | 53 ++++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index e866ed46a4..c57324d5e9 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -456,7 +456,7 @@ void ex_sort(exarg_T *eap) regmatch_T regmatch; int len; linenr_T lnum; - long maxlen = 0; + int maxlen = 0; size_t count = (size_t)(eap->line2 - eap->line1) + 1; size_t i; char *p; @@ -693,7 +693,7 @@ void ex_sort(exarg_T *eap) // Adjust marks for deleted (or added) lines and prepare for displaying. deleted = (linenr_T)count - (lnum - eap->line2); if (deleted > 0) { - mark_adjust(eap->line2 - deleted, eap->line2, (long)MAXLNUM, -deleted, kExtmarkNOOP); + mark_adjust(eap->line2 - deleted, eap->line2, MAXLNUM, -deleted, kExtmarkNOOP); msgmore(-deleted); } else if (deleted < 0) { mark_adjust(eap->line2, MAXLNUM, -deleted, 0L, kExtmarkNOOP); @@ -922,7 +922,7 @@ void ex_copy(linenr_T line1, linenr_T line2, linenr_T n) check_pos(curbuf, &VIsual); } - msgmore((long)count); + msgmore(count); } static char *prevcmd = NULL; // the previous command @@ -1281,7 +1281,7 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b set_keep_msg(msg_buf, 0); } } else { - msgmore((long)linecount); + msgmore(linecount); } } } else { @@ -3291,7 +3291,7 @@ static int check_regexp_delim(int c) /// @param cmdpreview_ns The namespace to show 'inccommand' preview highlights. /// If <= 0, preview shouldn't be shown. /// @return 0, 1 or 2. See show_cmdpreview() for more information on what the return value means. -static int do_sub(exarg_T *eap, const proftime_T timeout, const long cmdpreview_ns, +static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_ns, const handle_T cmdpreview_bufnr) { #define ADJUST_SUB_FIRSTLNUM() \ @@ -3318,7 +3318,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const long cmdpreview_ } \ } while (0) - long i = 0; + int i = 0; regmmatch_T regmatch; static subflags_T subflags = { .do_all = false, @@ -3346,7 +3346,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const long cmdpreview_ PreviewLines preview_lines = { KV_INITIAL_VALUE, 0 }; static int pre_hl_id = 0; pos_T old_cursor = curwin->w_cursor; - long start_nsubs; + int start_nsubs; bool did_save = false; @@ -3442,7 +3442,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const long cmdpreview_ // check for a trailing count cmd = skipwhite(cmd); if (ascii_isdigit(*cmd)) { - i = getdigits_long(&cmd, true, 0); + i = getdigits_int(&cmd, true, 0); if (i <= 0 && !eap->skip && subflags.do_error) { emsg(_(e_zerocount)); return 0; @@ -3521,8 +3521,8 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const long cmdpreview_ && (cmdpreview_ns <= 0 || preview_lines.lines_needed <= (linenr_T)p_cwh || lnum <= curwin->w_botline); lnum++) { - long nmatch = vim_regexec_multi(®match, curwin, curbuf, lnum, - (colnr_T)0, NULL, NULL); + int nmatch = (int)vim_regexec_multi(®match, curwin, curbuf, lnum, + (colnr_T)0, NULL, NULL); if (nmatch) { colnr_T copycol; colnr_T matchcol; @@ -3532,7 +3532,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const long cmdpreview_ char *p1; bool did_sub = false; int lastone; - long nmatch_tl = 0; // nr of lines matched below lnum + linenr_T nmatch_tl = 0; // nr of lines matched below lnum int do_again; // do it again after joining lines bool skip_match = false; linenr_T sub_firstlnum; // nr of first sub line @@ -3805,7 +3805,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const long cmdpreview_ // Same highlight as wait_return(). smsg(HL_ATTR(HLF_R), _("replace with %s (y/n/a/q/l/^E/^Y)?"), sub); msg_no_more = false; - msg_scroll = (int)i; + msg_scroll = i; if (!ui_has(kUIMessages)) { ui_cursor_goto(msg_row, msg_col); } @@ -4087,9 +4087,9 @@ skip: // need to replace the line first (using \zs after \n). if (lastone || nmatch_tl > 0 - || (nmatch = vim_regexec_multi(®match, curwin, - curbuf, sub_firstlnum, - matchcol, NULL, NULL)) == 0 + || (nmatch = (int)vim_regexec_multi(®match, curwin, + curbuf, sub_firstlnum, + matchcol, NULL, NULL)) == 0 || regmatch.startpos[0].lnum > 0) { if (new_start != NULL) { // Copy the rest of the line, that didn't match. @@ -4119,13 +4119,12 @@ skip: for (i = 0; i < nmatch_tl; i++) { ml_delete(lnum, false); } - mark_adjust(lnum, lnum + (linenr_T)nmatch_tl - 1, - (long)MAXLNUM, (linenr_T)(-nmatch_tl), kExtmarkNOOP); + mark_adjust(lnum, lnum + nmatch_tl - 1, MAXLNUM, -nmatch_tl, kExtmarkNOOP); if (subflags.do_ask) { - deleted_lines(lnum, (linenr_T)nmatch_tl); + deleted_lines(lnum, nmatch_tl); } lnum--; - line2 -= (linenr_T)nmatch_tl; // nr of lines decreases + line2 -= nmatch_tl; // nr of lines decreases nmatch_tl = 0; } @@ -4150,8 +4149,8 @@ skip: copycol = 0; } if (nmatch == -1 && !lastone) { - nmatch = vim_regexec_multi(®match, curwin, curbuf, - sub_firstlnum, matchcol, NULL, NULL); + nmatch = (int)vim_regexec_multi(®match, curwin, curbuf, + sub_firstlnum, matchcol, NULL, NULL); } // 5. break if there isn't another match in this line @@ -4582,7 +4581,7 @@ bool prepare_tagpreview(bool undo_sync) /// /// @return 1 if preview window isn't needed, 2 if preview window is needed. static int show_sub(exarg_T *eap, pos_T old_cusr, PreviewLines *preview_lines, int hl_id, - long cmdpreview_ns, handle_T cmdpreview_bufnr) + int cmdpreview_ns, handle_T cmdpreview_bufnr) FUNC_ATTR_NONNULL_ALL { char *save_shm_p = xstrdup(p_shm); @@ -4684,9 +4683,9 @@ static int show_sub(exarg_T *eap, pos_T old_cusr, PreviewLines *preview_lines, i } linenr_origbuf = match.end.lnum; - bufhl_add_hl_pos_offset(cmdpreview_buf, (int)cmdpreview_ns, hl_id, p_start, p_end, col_width); + bufhl_add_hl_pos_offset(cmdpreview_buf, cmdpreview_ns, hl_id, p_start, p_end, col_width); } - bufhl_add_hl_pos_offset(orig_buf, (int)cmdpreview_ns, hl_id, match.start, match.end, 0); + bufhl_add_hl_pos_offset(orig_buf, cmdpreview_ns, hl_id, match.start, match.end, 0); } xfree(str); @@ -4704,7 +4703,7 @@ void ex_substitute(exarg_T *eap) } /// :substitute command preview callback. -int ex_substitute_preview(exarg_T *eap, long cmdpreview_ns, handle_T cmdpreview_bufnr) +int ex_substitute_preview(exarg_T *eap, int cmdpreview_ns, handle_T cmdpreview_bufnr) { // Only preview once the pattern delimiter has been typed if (*eap->arg && !ASCII_ISALNUM(*eap->arg)) { @@ -4773,7 +4772,7 @@ char *skip_vimgrep_pat(char *p, char **s, int *flags) void ex_oldfiles(exarg_T *eap) { list_T *l = get_vim_var_list(VV_OLDFILES); - long nr = 0; + int nr = 0; if (l == NULL) { msg(_("No old files"), 0); @@ -4807,7 +4806,7 @@ void ex_oldfiles(exarg_T *eap) nr = prompt_for_number(false); msg_starthere(); if (nr > 0 && nr <= tv_list_len(l)) { - const char *const p = tv_list_find_str(l, (int)nr - 1); + const char *const p = tv_list_find_str(l, nr - 1); if (p == NULL) { return; } -- cgit From 8e932480f61d6101bf8bea1abc07ed93826221fd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/ex_cmds.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index c57324d5e9..e9a42ae508 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3521,8 +3521,8 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n && (cmdpreview_ns <= 0 || preview_lines.lines_needed <= (linenr_T)p_cwh || lnum <= curwin->w_botline); lnum++) { - int nmatch = (int)vim_regexec_multi(®match, curwin, curbuf, lnum, - (colnr_T)0, NULL, NULL); + int nmatch = vim_regexec_multi(®match, curwin, curbuf, lnum, + (colnr_T)0, NULL, NULL); if (nmatch) { colnr_T copycol; colnr_T matchcol; @@ -4087,9 +4087,9 @@ skip: // need to replace the line first (using \zs after \n). if (lastone || nmatch_tl > 0 - || (nmatch = (int)vim_regexec_multi(®match, curwin, - curbuf, sub_firstlnum, - matchcol, NULL, NULL)) == 0 + || (nmatch = vim_regexec_multi(®match, curwin, + curbuf, sub_firstlnum, + matchcol, NULL, NULL)) == 0 || regmatch.startpos[0].lnum > 0) { if (new_start != NULL) { // Copy the rest of the line, that didn't match. @@ -4149,8 +4149,8 @@ skip: copycol = 0; } if (nmatch == -1 && !lastone) { - nmatch = (int)vim_regexec_multi(®match, curwin, curbuf, - sub_firstlnum, matchcol, NULL, NULL); + nmatch = vim_regexec_multi(®match, curwin, curbuf, + sub_firstlnum, matchcol, NULL, NULL); } // 5. break if there isn't another match in this line @@ -4446,7 +4446,7 @@ void ex_global(exarg_T *eap) if (global_busy) { lnum = curwin->w_cursor.lnum; - match = (int)vim_regexec_multi(®match, curwin, curbuf, lnum, 0, NULL, NULL); + match = vim_regexec_multi(®match, curwin, curbuf, lnum, 0, NULL, NULL); if ((type == 'g' && match) || (type == 'v' && !match)) { global_exe_one(cmd, lnum); } @@ -4455,7 +4455,7 @@ void ex_global(exarg_T *eap) // pass 1: set marks for each (not) matching line for (lnum = eap->line1; lnum <= eap->line2 && !got_int; lnum++) { // a match on this line? - match = (int)vim_regexec_multi(®match, curwin, curbuf, lnum, 0, NULL, NULL); + match = vim_regexec_multi(®match, curwin, curbuf, lnum, 0, NULL, NULL); if (regmatch.regprog == NULL) { break; // re-compiling regprog failed } -- cgit From 13f55750e9bea8ec8f50550546edc64a0f0964d8 Mon Sep 17 00:00:00 2001 From: nwounkn Date: Fri, 13 Oct 2023 12:01:26 +0500 Subject: fix(ui): empty line before the next message after :silent command Problem: The next command after `silent !{cmd}` or `silent lua print('str')` prints an empty line before printing a message, because these commands set `msg_didout = true` despite not printing any messages. Solution: Set `msg_didout = true` only if `msg_silent == 0` --- src/nvim/ex_cmds.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index e9a42ae508..5ec4353e1d 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1346,7 +1346,9 @@ void do_shell(char *cmd, int flags) // 1" command to the terminal. ui_cursor_goto(msg_row, msg_col); (void)call_shell(cmd, (ShellOpts)flags, NULL); - msg_didout = true; + if (msg_silent == 0) { + msg_didout = true; + } did_check_timestamps = false; need_check_timestamps = true; -- cgit From 5f03a1eaabfc8de2b3a9c666fcd604763f41e152 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 20 Oct 2023 15:10:33 +0200 Subject: build(lint): remove unnecessary clint.py rules Uncrustify is the source of truth where possible. Remove any redundant checks from clint.py. --- src/nvim/ex_cmds.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 5ec4353e1d..fa10dd0805 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3341,7 +3341,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n int which_pat; char *cmd = eap->arg; linenr_T first_line = 0; // first changed line - linenr_T last_line= 0; // below last changed line AFTER the change + linenr_T last_line = 0; // below last changed line AFTER the change linenr_T old_line_count = curbuf->b_ml.ml_line_count; char *sub_firstline; // allocated copy of first sub line bool endcolumn = false; // cursor in last column when done @@ -3601,7 +3601,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n while (true) { SubResult current_match = { .start = { 0, 0 }, - .end = { 0, 0 }, + .end = { 0, 0 }, .pre_match = 0, }; // lnum is where the match start, but maybe not the pattern match, @@ -3905,7 +3905,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n if (current_match.end.lnum == 0) { current_match.end.lnum = sub_firstlnum + (linenr_T)nmatch - 1; } - current_match.end.col = regmatch.endpos[0].col; + current_match.end.col = regmatch.endpos[0].col; ADJUST_SUB_FIRSTLNUM(); lnum += (linenr_T)nmatch - 1; @@ -4636,7 +4636,7 @@ static int show_sub(exarg_T *eap, pos_T old_cusr, PreviewLines *preview_lines, i if (cmdpreview_buf) { lpos_T p_start = { 0, match.start.col }; // match starts here in preview - lpos_T p_end = { 0, match.end.col }; // ... and ends here + lpos_T p_end = { 0, match.end.col }; // ... and ends here // You Might Gonna Need It buf_ensure_loaded(cmdpreview_buf); -- cgit From acc646ad8fc3ef11fcc63b69f3d8484e4a91accd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/ex_cmds.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index fa10dd0805..2857465db0 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -323,7 +323,7 @@ void ex_align(exarg_T *eap) } (void)set_indent(new_indent, 0); // set indent } - changed_lines(curbuf, eap->line1, 0, eap->line2 + 1, 0L, true); + changed_lines(curbuf, eap->line1, 0, eap->line2 + 1, 0, true); curwin->w_cursor = save_curpos; beginline(BL_WHITE | BL_FIX); } @@ -696,7 +696,7 @@ void ex_sort(exarg_T *eap) mark_adjust(eap->line2 - deleted, eap->line2, MAXLNUM, -deleted, kExtmarkNOOP); msgmore(-deleted); } else if (deleted < 0) { - mark_adjust(eap->line2, MAXLNUM, -deleted, 0L, kExtmarkNOOP); + mark_adjust(eap->line2, MAXLNUM, -deleted, 0, kExtmarkNOOP); } if (change_occurred || deleted != 0) { @@ -783,7 +783,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) // And Finally we adjust the marks we put at the end of the file back to // their final destination at the new text position -- webb last_line = curbuf->b_ml.ml_line_count; - mark_adjust_nofold(line1, line2, last_line - line2, 0L, kExtmarkNOOP); + mark_adjust_nofold(line1, line2, last_line - line2, 0, kExtmarkNOOP); disable_fold_update++; changed_lines(curbuf, last_line - num_lines + 1, 0, last_line + 1, num_lines, false); @@ -792,7 +792,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) int line_off = 0; bcount_t byte_off = 0; if (dest >= line2) { - mark_adjust_nofold(line2 + 1, dest, -num_lines, 0L, kExtmarkNOOP); + mark_adjust_nofold(line2 + 1, dest, -num_lines, 0, kExtmarkNOOP); FOR_ALL_TAB_WINDOWS(tab, win) { if (win->w_buffer == curbuf) { foldMoveRange(win, &win->w_folds, line1, line2, dest); @@ -805,7 +805,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) line_off = -num_lines; byte_off = -extent_byte; } else { - mark_adjust_nofold(dest + 1, line1 - 1, num_lines, 0L, kExtmarkNOOP); + mark_adjust_nofold(dest + 1, line1 - 1, num_lines, 0, kExtmarkNOOP); FOR_ALL_TAB_WINDOWS(tab, win) { if (win->w_buffer == curbuf) { foldMoveRange(win, &win->w_folds, dest + 1, line1 - 1, line2); @@ -820,7 +820,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) curbuf->b_op_start.col = curbuf->b_op_end.col = 0; } mark_adjust_nofold(last_line - num_lines + 1, last_line, - -(last_line - dest - extra), 0L, kExtmarkNOOP); + -(last_line - dest - extra), 0, kExtmarkNOOP); disable_fold_update++; changed_lines(curbuf, last_line - num_lines + 1, 0, last_line + 1, -extra, false); @@ -861,9 +861,9 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) if (dest > last_line + 1) { dest = last_line + 1; } - changed_lines(curbuf, line1, 0, dest, 0L, false); + changed_lines(curbuf, line1, 0, dest, 0, false); } else { - changed_lines(curbuf, dest + 1, 0, line1 + num_lines, 0L, false); + changed_lines(curbuf, dest + 1, 0, line1 + num_lines, 0, false); } // send nvim_buf_lines_event regarding lines that were deleted @@ -1243,13 +1243,13 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b // end of each line? if (read_linecount >= linecount) { // move all marks from old lines to new lines - mark_adjust(line1, line2, linecount, 0L, kExtmarkNOOP); + mark_adjust(line1, line2, linecount, 0, kExtmarkNOOP); } else { // move marks from old lines to new lines, delete marks // that are in deleted lines - mark_adjust(line1, line1 + read_linecount - 1, linecount, 0L, + mark_adjust(line1, line1 + read_linecount - 1, linecount, 0, kExtmarkNOOP); - mark_adjust(line1 + read_linecount, line2, MAXLNUM, 0L, + mark_adjust(line1 + read_linecount, line2, MAXLNUM, 0, kExtmarkNOOP); } } @@ -2283,7 +2283,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum if (command != NULL) { tlnum = (linenr_T)atol(command); if (tlnum <= 0) { - tlnum = 1L; + tlnum = 1; } } // Add BLN_NOCURWIN to avoid a new wininfo items are associated @@ -2295,7 +2295,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum } goto theend; } - buf = buflist_new(ffname, sfname, 0L, + buf = buflist_new(ffname, sfname, 0, BLN_CURBUF | (flags & ECMD_SET_HELP ? 0 : BLN_LISTED)); // Autocmds may change curwin and curbuf. if (oldwin != NULL) { @@ -2861,16 +2861,16 @@ void ex_append(exarg_T *eap) ml_append(lnum, theline, (colnr_T)0, false); if (empty) { // there are no marks below the inserted lines - appended_lines(lnum, 1L); + appended_lines(lnum, 1); } else { - appended_lines_mark(lnum, 1L); + appended_lines_mark(lnum, 1); } xfree(theline); lnum++; if (empty) { - ml_delete(2L, false); + ml_delete(2, false); empty = 0; } } @@ -4020,10 +4020,10 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n *p1 = NUL; // truncate up to the CR ml_append(lnum - 1, new_start, (colnr_T)(p1 - new_start + 1), false); - mark_adjust(lnum + 1, (linenr_T)MAXLNUM, 1L, 0L, kExtmarkNOOP); + mark_adjust(lnum + 1, (linenr_T)MAXLNUM, 1, 0, kExtmarkNOOP); if (subflags.do_ask) { - appended_lines(lnum - 1, 1L); + appended_lines(lnum - 1, 1); } else { if (first_line == 0) { first_line = lnum; -- cgit From cd63a9addd6e1114c3524fa041ece560550cfe7b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 10 Nov 2023 08:39:21 +0800 Subject: refactor: change some xstrndup() and xstrnsave() to xmemdupz() (#25959) When the given length is exactly the number of bytes to copy, xmemdupz() makes the intention clearer. --- src/nvim/ex_cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 2857465db0..bb3284a6b8 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -2816,7 +2816,7 @@ void ex_append(exarg_T *eap) if (p == NULL) { p = eap->nextcmd + strlen(eap->nextcmd); } - theline = xstrnsave(eap->nextcmd, (size_t)(p - eap->nextcmd)); + theline = xmemdupz(eap->nextcmd, (size_t)(p - eap->nextcmd)); if (*p != NUL) { p++; } -- cgit From 8e58d37f2e15ac8540377148e55ed08a039aadb6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 11 Nov 2023 11:20:08 +0100 Subject: refactor: remove redundant casts --- src/nvim/ex_cmds.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index bb3284a6b8..7400501ee3 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -670,7 +670,7 @@ void ex_sort(exarg_T *eap) // Copy the line into a buffer, it may become invalid in // ml_append(). And it's needed for "unique". STRCPY(sortbuf1, s); - if (ml_append(lnum++, sortbuf1, (colnr_T)0, false) == FAIL) { + if (ml_append(lnum++, sortbuf1, 0, false) == FAIL) { break; } new_count += (bcount_t)bytelen; @@ -762,7 +762,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) } for (extra = 0, l = line1; l <= line2; l++) { char *str = xstrdup(ml_get(l + extra)); - ml_append(dest + l - line1, str, (colnr_T)0, false); + ml_append(dest + l - line1, str, 0, false); xfree(str); if (dest < line1) { extra++; @@ -900,7 +900,7 @@ void ex_copy(linenr_T line1, linenr_T line2, linenr_T n) // need to use xstrdup() because the line will be unlocked within // ml_append() char *p = xstrdup(ml_get(line1)); - ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, false); + ml_append(curwin->w_cursor.lnum, p, 0, false); xfree(p); // situation 2: skip already copied lines @@ -1214,7 +1214,7 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b if (do_out) { if (otmp != NULL) { - if (readfile(otmp, NULL, line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, + if (readfile(otmp, NULL, line2, 0, (linenr_T)MAXLNUM, eap, READ_FILTER, false) != OK) { if (!aborting()) { msg_putchar('\n'); @@ -1682,7 +1682,7 @@ int do_write(exarg_T *eap) if (other) { if (vim_strchr(p_cpo, CPO_ALTWRITE) != NULL || eap->cmdidx == CMD_saveas) { - alt_buf = setaltfname(ffname, fname, (linenr_T)1); + alt_buf = setaltfname(ffname, fname, 1); } else { alt_buf = buflist_findname(ffname); } @@ -2243,7 +2243,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum oldwin = NULL; } - if ((command != NULL || newlnum > (linenr_T)0) + if ((command != NULL || newlnum > 0) && *get_vim_var_str(VV_SWAPCOMMAND) == NUL) { // Set v:swapcommand for the SwapExists autocommands. const size_t len = (command != NULL) ? strlen(command) + 3 : 30; @@ -2858,7 +2858,7 @@ void ex_append(exarg_T *eap) } did_undo = true; - ml_append(lnum, theline, (colnr_T)0, false); + ml_append(lnum, theline, 0, false); if (empty) { // there are no marks below the inserted lines appended_lines(lnum, 1); @@ -3524,7 +3524,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n || lnum <= curwin->w_botline); lnum++) { int nmatch = vim_regexec_multi(®match, curwin, curbuf, lnum, - (colnr_T)0, NULL, NULL); + 0, NULL, NULL); if (nmatch) { colnr_T copycol; colnr_T matchcol; -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/ex_cmds.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 7400501ee3..19d1bdc8e6 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - // ex_cmds.c: some functions for command line commands #include -- cgit From 28f4f3c48498086307ed825d1761edb5789ca0e8 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 15:54:54 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment - use bool to represent boolean values --- src/nvim/ex_cmds.c | 102 ++++++++++++++++++----------------------------------- 1 file changed, 35 insertions(+), 67 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 19d1bdc8e6..94f981dc2b 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -238,12 +238,8 @@ void do_ascii(exarg_T *eap) /// ":left", ":center" and ":right": align text. void ex_align(exarg_T *eap) { - pos_T save_curpos; - int len; int indent = 0; int new_indent; - int has_tab; - int width; if (curwin->w_p_rl) { // switch left and right aligning @@ -254,8 +250,8 @@ void ex_align(exarg_T *eap) } } - width = atoi(eap->arg); - save_curpos = curwin->w_cursor; + int width = atoi(eap->arg); + pos_T save_curpos = curwin->w_cursor; if (eap->cmdidx == CMD_left) { // width is used for new indent if (width >= 0) { indent = width; @@ -284,8 +280,8 @@ void ex_align(exarg_T *eap) if (eap->cmdidx == CMD_left) { // left align new_indent = indent; } else { - has_tab = false; // avoid uninit warnings - len = linelen(eap->cmdidx == CMD_right ? &has_tab : NULL) - get_indent(); + int has_tab = false; // avoid uninit warnings + int len = linelen(eap->cmdidx == CMD_right ? &has_tab : NULL) - get_indent(); if (len <= 0) { // skip blank lines continue; @@ -328,26 +324,23 @@ void ex_align(exarg_T *eap) /// @return the length of the current line, excluding trailing white space. static int linelen(int *has_tab) { - char *line; - char *first; char *last; - int len; // Get the line. If it's empty bail out early (could be the empty string // for an unloaded buffer). - line = get_cursor_line_ptr(); + char *line = get_cursor_line_ptr(); if (*line == NUL) { return 0; } // find the first non-blank character - first = skipwhite(line); + char *first = skipwhite(line); // find the character after the last non-blank character for (last = first + strlen(first); last > first && ascii_iswhite(last[-1]); last--) {} char save = *last; *last = NUL; - len = linetabsize_str(line); // Get line length. + int len = linetabsize_str(line); // Get line length. if (has_tab != NULL) { // Check for embedded TAB. *has_tab = vim_strchr(first, TAB) != NULL; } @@ -451,19 +444,11 @@ static int sort_compare(const void *s1, const void *s2) void ex_sort(exarg_T *eap) { regmatch_T regmatch; - int len; linenr_T lnum; int maxlen = 0; size_t count = (size_t)(eap->line2 - eap->line1) + 1; size_t i; - char *p; - char *s; - char *s2; - char c; // temporary character storage bool unique = false; - linenr_T deleted; - colnr_T start_col; - colnr_T end_col; int sort_what = 0; // Sorting one line is really quick! @@ -483,7 +468,7 @@ void ex_sort(exarg_T *eap) size_t format_found = 0; bool change_occurred = false; // Buffer contents changed. - for (p = eap->arg; *p != NUL; p++) { + for (char *p = eap->arg; *p != NUL; p++) { if (ascii_iswhite(*p)) { // Skip } else if (*p == 'i') { @@ -516,7 +501,7 @@ void ex_sort(exarg_T *eap) eap->nextcmd = check_nextcmd(p); break; } else if (!ASCII_ISALPHA(*p) && regmatch.regprog == NULL) { - s = skip_regexp_err(p + 1, *p, true); + char *s = skip_regexp_err(p + 1, *p, true); if (s == NULL) { goto sortend; } @@ -559,14 +544,14 @@ void ex_sort(exarg_T *eap) // matching and number conversion only has to be done once per line. // Also get the longest line length for allocating "sortbuf". for (lnum = eap->line1; lnum <= eap->line2; lnum++) { - s = ml_get(lnum); - len = (int)strlen(s); + char *s = ml_get(lnum); + int len = (int)strlen(s); if (maxlen < len) { maxlen = len; } - start_col = 0; - end_col = len; + colnr_T start_col = 0; + colnr_T end_col = len; if (regmatch.regprog != NULL && vim_regexec(®match, s, 0)) { if (sort_rx) { start_col = (colnr_T)(regmatch.startp[0] - s); @@ -581,11 +566,11 @@ void ex_sort(exarg_T *eap) if (sort_nr || sort_flt) { // Make sure vim_str2nr() doesn't read any digits past the end // of the match, by temporarily terminating the string there - s2 = s + end_col; - c = *s2; + char *s2 = s + end_col; + char c = *s2; // temporary character storage *s2 = NUL; // Sorting on number: Store the number itself. - p = s + start_col; + char *p = s + start_col; if (sort_nr) { if (sort_what & STR2NR_HEX) { s = skiptohex(p); @@ -660,7 +645,7 @@ void ex_sort(exarg_T *eap) change_occurred = true; } - s = ml_get(get_lnum); + char *s = ml_get(get_lnum); size_t bytelen = strlen(s) + 1; // include EOL in bytelen old_count += (bcount_t)bytelen; if (!unique || i == 0 || string_compare(s, sortbuf1) != 0) { @@ -688,7 +673,7 @@ void ex_sort(exarg_T *eap) } // Adjust marks for deleted (or added) lines and prepare for displaying. - deleted = (linenr_T)count - (lnum - eap->line2); + linenr_T deleted = (linenr_T)count - (lnum - eap->line2); if (deleted > 0) { mark_adjust(eap->line2 - deleted, eap->line2, MAXLNUM, -deleted, kExtmarkNOOP); msgmore(-deleted); @@ -954,14 +939,9 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out linenr_T line2 = eap->line2; // end of range char *newcmd = NULL; // the new command bool free_newcmd = false; // need to free() newcmd - char *t; - char *p; - char *trailarg; int scroll_save = msg_scroll; - // // Disallow shell commands in secure mode - // if (check_secure()) { return; } @@ -977,7 +957,7 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out bool ins_prevcmd = forceit; // Skip leading white space to avoid a strange error with some shells. - trailarg = skipwhite(arg); + char *trailarg = skipwhite(arg); do { size_t len = strlen(trailarg) + 1; if (newcmd != NULL) { @@ -990,7 +970,7 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } len += strlen(prevcmd); } - t = xmalloc(len); + char *t = xmalloc(len); *t = NUL; if (newcmd != NULL) { STRCAT(t, newcmd); @@ -998,7 +978,7 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out if (ins_prevcmd) { STRCAT(t, prevcmd); } - p = t + strlen(t); + char *p = t + strlen(t); STRCAT(t, trailarg); xfree(newcmd); newcmd = t; @@ -1099,10 +1079,6 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b { char *itmp = NULL; char *otmp = NULL; - linenr_T linecount; - linenr_T read_linecount; - pos_T cursor_save; - char *cmd_buf; buf_T *old_curbuf = curbuf; int shell_flags = 0; const pos_T orig_start = curbuf->b_op_start; @@ -1118,8 +1094,8 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b // regions of the buffer for foldUpdate(), linecount, etc. cmdmod.cmod_flags &= ~CMOD_LOCKMARKS; - cursor_save = curwin->w_cursor; - linecount = line2 - line1 + 1; + pos_T cursor_save = curwin->w_cursor; + linenr_T linecount = line2 - line1 + 1; curwin->w_cursor.lnum = line1; curwin->w_cursor.col = 0; changed_line_abv_curs(); @@ -1184,7 +1160,7 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b } // Create the shell command in allocated memory. - cmd_buf = make_filter_cmd(cmd, itmp, otmp); + char *cmd_buf = make_filter_cmd(cmd, itmp, otmp); ui_cursor_goto(Rows - 1, 0); if (do_out) { @@ -1194,7 +1170,7 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b } redraw_curbuf_later(UPD_VALID); } - read_linecount = curbuf->b_ml.ml_line_count; + linenr_T read_linecount = curbuf->b_ml.ml_line_count; // Pass on the kShellOptDoOut flag when the output is being redirected. call_shell(cmd_buf, (ShellOpts)(kShellOptFilter | shell_flags), NULL); @@ -1534,10 +1510,7 @@ void print_line(linenr_T lnum, int use_number, int list) int rename_buffer(char *new_fname) { - char *fname, *sfname, *xfname; - buf_T *buf; - - buf = curbuf; + buf_T *buf = curbuf; apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, false, curbuf); // buffer changed, don't change name now if (buf != curbuf) { @@ -1551,9 +1524,9 @@ int rename_buffer(char *new_fname) // name, which will become the alternate file name. // But don't set the alternate file name if the buffer didn't have a // name. - fname = curbuf->b_ffname; - sfname = curbuf->b_sfname; - xfname = curbuf->b_fname; + char *fname = curbuf->b_ffname; + char *sfname = curbuf->b_sfname; + char *xfname = curbuf->b_fname; curbuf->b_ffname = NULL; curbuf->b_sfname = NULL; if (setfname(curbuf, new_fname, NULL, true) == FAIL) { @@ -1647,7 +1620,6 @@ int do_write(exarg_T *eap) { int other; char *fname = NULL; // init to shut up gcc - char *ffname; int retval = FAIL; char *free_fname = NULL; buf_T *alt_buf = NULL; @@ -1657,7 +1629,7 @@ int do_write(exarg_T *eap) return FAIL; } - ffname = eap->arg; + char *ffname = eap->arg; if (*ffname == NUL) { if (eap->cmdidx == CMD_saveas) { emsg(_(e_argreq)); @@ -2931,12 +2903,9 @@ void ex_change(exarg_T *eap) void ex_z(exarg_T *eap) { - char *x; int64_t bigness; - char *kind; int minus = 0; linenr_T start, end, curs, i; - int j; linenr_T lnum = eap->line2; // Vi compatible: ":z!" uses display height, without a count uses @@ -2952,8 +2921,8 @@ void ex_z(exarg_T *eap) bigness = 1; } - x = eap->arg; - kind = x; + char *x = eap->arg; + char *kind = x; if (*kind == '-' || *kind == '+' || *kind == '=' || *kind == '^' || *kind == '.') { x++; @@ -3041,7 +3010,7 @@ void ex_z(exarg_T *eap) if (minus && i == lnum) { msg_putchar('\n'); - for (j = 1; j < Columns; j++) { + for (int j = 1; j < Columns; j++) { msg_putchar('-'); } } @@ -3051,7 +3020,7 @@ void ex_z(exarg_T *eap) if (minus && i == lnum) { msg_putchar('\n'); - for (j = 1; j < Columns; j++) { + for (int j = 1; j < Columns; j++) { msg_putchar('-'); } } @@ -4386,7 +4355,6 @@ void ex_global(exarg_T *eap) char *pat; regmmatch_T regmatch; int match; - int which_pat; // When nesting the command works on one line. This allows for // ":g/found/v/notfound/command". @@ -4403,7 +4371,7 @@ void ex_global(exarg_T *eap) type = (uint8_t)(*eap->cmd); } cmd = eap->arg; - which_pat = RE_LAST; // default: use last used regexp + int which_pat = RE_LAST; // default: use last used regexp // undocumented vi feature: // "\/" and "\?": use previous search pattern. -- cgit From bb4b4576e384c71890b4df4fa4f1ae76fad3a59d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 16 Nov 2023 10:55:54 +0800 Subject: refactor: iwyu (#26062) --- src/nvim/ex_cmds.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 94f981dc2b..521f8eb208 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -73,6 +73,7 @@ #include "nvim/os/time.h" #include "nvim/path.h" #include "nvim/plines.h" +#include "nvim/pos.h" #include "nvim/profile.h" #include "nvim/quickfix.h" #include "nvim/regexp.h" -- cgit From a4c111ae690448176ae584b9a2181923d1b2cdbd Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 17 Nov 2023 06:41:03 +0800 Subject: vim-patch:9.0.2108: [security]: overflow with count for :s command Problem: [security]: overflow with count for :s command Solution: Abort the :s command if the count is too large If the count after the :s command is larger than what fits into a (signed) long variable, abort with e_value_too_large. Adds a test with INT_MAX as count and verify it correctly fails. It seems the return value on Windows using mingw compiler wraps around, so the initial test using :s/./b/9999999999999999999999999990 doesn't fail there, since the count is wrapping around several times and finally is no longer larger than 2147483647. So let's just use 2147483647 in the test, which hopefully will always cause a failure https://github.com/vim/vim/commit/ac63787734fda2e294e477af52b3bd601517fa78 Co-authored-by: Christian Brabandt --- src/nvim/ex_cmds.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 521f8eb208..692b320335 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3411,10 +3411,15 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n // check for a trailing count cmd = skipwhite(cmd); if (ascii_isdigit(*cmd)) { - i = getdigits_int(&cmd, true, 0); + i = getdigits_int(&cmd, true, INT_MAX); if (i <= 0 && !eap->skip && subflags.do_error) { emsg(_(e_zerocount)); return 0; + } else if (i >= INT_MAX) { + char buf[20]; + vim_snprintf(buf, sizeof(buf), "%d", i); + semsg(_(e_val_too_large), buf); + return 0; } eap->line1 = eap->line2; eap->line2 += (linenr_T)i - 1; -- cgit From b522cb1ac3fbdf6e68eed5d0b6e1cbeaf3ac2254 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 6 Nov 2023 14:52:27 +0100 Subject: refactor(grid): make screen rendering more multibyte than ever before Problem: buffer text with composing chars are converted from UTF-8 to an array of up to seven UTF-32 values and then converted back to UTF-8 strings. Solution: Convert buffer text directly to UTF-8 based schar_T values. The limit of the text size is now in schar_T bytes, which is currently 31+1 but easily could be raised as it no longer multiplies the size of the entire screen grid when not used, the full size is only required for temporary scratch buffers. Also does some general cleanup to win_line text handling, which was unnecessarily complicated due to multibyte rendering being an "opt-in" feature long ago. Nowadays, a char is just a char, regardless if it consists of one ASCII byte or multiple bytes. --- src/nvim/ex_cmds.c | 110 +++++++++++++++++++++++------------------------------ 1 file changed, 48 insertions(+), 62 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 692b320335..d92be6404b 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -131,17 +131,22 @@ static const char e_non_numeric_argument_to_z[] /// ":ascii" and "ga" implementation void do_ascii(exarg_T *eap) { - char *dig; - int cc[MAX_MCO]; - int c = utfc_ptr2char(get_cursor_pos_ptr(), cc); - if (c == NUL) { + char *data = get_cursor_pos_ptr(); + size_t len = (size_t)utfc_ptr2len(data); + + if (len == 0) { msg("NUL", 0); return; } - size_t iobuff_len = 0; + bool need_clear = true; + msg_sb_eol(); + msg_start(); + + int c = utf_ptr2char(data); + size_t off = 0; - int ci = 0; + // TODO(bfredl): merge this with the main loop if (c < 0x80) { if (c == NL) { // NUL is stored as NL. c = NUL; @@ -160,46 +165,29 @@ void do_ascii(exarg_T *eap) char buf2[20]; buf2[0] = NUL; - dig = get_digraph_for_char(cval); + char *dig = get_digraph_for_char(cval); if (dig != NULL) { - iobuff_len += (size_t)vim_snprintf(IObuff + iobuff_len, - sizeof(IObuff) - iobuff_len, - _("<%s>%s%s %d, Hex %02x, Oct %03o, Digr %s"), - transchar(c), buf1, buf2, cval, cval, cval, dig); + vim_snprintf(IObuff, sizeof(IObuff), + _("<%s>%s%s %d, Hex %02x, Oct %03o, Digr %s"), + transchar(c), buf1, buf2, cval, cval, cval, dig); } else { - iobuff_len += (size_t)vim_snprintf(IObuff + iobuff_len, - sizeof(IObuff) - iobuff_len, - _("<%s>%s%s %d, Hex %02x, Octal %03o"), - transchar(c), buf1, buf2, cval, cval, cval); - } - - c = cc[ci++]; - } - -#define SPACE_FOR_DESC (1 + 1 + 1 + MB_MAXBYTES + 16 + 4 + 3 + 3 + 1) - // Space for description: - // - 1 byte for separator (starting from second entry) - // - 1 byte for "<" - // - 1 byte for space to draw composing character on (optional, but really - // mostly required) - // - up to MB_MAXBYTES bytes for character itself - // - 16 bytes for raw text ("> , Hex , Octal "). - // - at least 4 bytes for hexadecimal representation - // - at least 3 bytes for decimal representation - // - at least 3 bytes for octal representation - // - 1 byte for NUL - // - // Taking into account MAX_MCO and characters which need 8 bytes for - // hexadecimal representation, but not taking translation into account: - // resulting string will occupy less then 400 bytes (conservative estimate). - // - // Less then 1000 bytes if translation multiplies number of bytes needed for - // raw text by 6, so it should always fit into 1025 bytes reserved for IObuff. + vim_snprintf(IObuff, sizeof(IObuff), + _("<%s>%s%s %d, Hex %02x, Octal %03o"), + transchar(c), buf1, buf2, cval, cval, cval); + } + + msg_multiline(IObuff, 0, true, &need_clear); + + off += (size_t)utf_ptr2len(data); // needed for overlong ascii? + } // Repeat for combining characters, also handle multiby here. - while (c >= 0x80 && iobuff_len < sizeof(IObuff) - SPACE_FOR_DESC) { + while (off < len) { + c = utf_ptr2char(data + off); + + size_t iobuff_len = 0; // This assumes every multi-byte char is printable... - if (iobuff_len > 0) { + if (off > 0) { IObuff[iobuff_len++] = ' '; } IObuff[iobuff_len++] = '<'; @@ -208,32 +196,30 @@ void do_ascii(exarg_T *eap) } iobuff_len += (size_t)utf_char2bytes(c, IObuff + iobuff_len); - dig = get_digraph_for_char(c); + char *dig = get_digraph_for_char(c); if (dig != NULL) { - iobuff_len += (size_t)vim_snprintf(IObuff + iobuff_len, - sizeof(IObuff) - iobuff_len, - (c < 0x10000 - ? _("> %d, Hex %04x, Oct %o, Digr %s") - : _("> %d, Hex %08x, Oct %o, Digr %s")), - c, c, c, dig); + vim_snprintf(IObuff + iobuff_len, sizeof(IObuff) - iobuff_len, + (c < 0x10000 + ? _("> %d, Hex %04x, Oct %o, Digr %s") + : _("> %d, Hex %08x, Oct %o, Digr %s")), + c, c, c, dig); } else { - iobuff_len += (size_t)vim_snprintf(IObuff + iobuff_len, - sizeof(IObuff) - iobuff_len, - (c < 0x10000 - ? _("> %d, Hex %04x, Octal %o") - : _("> %d, Hex %08x, Octal %o")), - c, c, c); - } - if (ci == MAX_MCO) { - break; + vim_snprintf(IObuff + iobuff_len, sizeof(IObuff) - iobuff_len, + (c < 0x10000 + ? _("> %d, Hex %04x, Octal %o") + : _("> %d, Hex %08x, Octal %o")), + c, c, c); } - c = cc[ci++]; - } - if (ci != MAX_MCO && c != 0) { - xstrlcpy(IObuff + iobuff_len, " ...", sizeof(IObuff) - iobuff_len); + + msg_multiline(IObuff, 0, true, &need_clear); + + off += (size_t)utf_ptr2len(data + off); // needed for overlong ascii? } - msg(IObuff, 0); + if (need_clear) { + msg_clr_eos(); + } + msg_end(); } /// ":left", ":center" and ":right": align text. -- cgit From ac1113ded5f8f09dd99a9894d7a7e795626fb728 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 13 Nov 2023 23:40:37 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment --- src/nvim/ex_cmds.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index d92be6404b..9a285bfe75 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -431,7 +431,6 @@ static int sort_compare(const void *s1, const void *s2) void ex_sort(exarg_T *eap) { regmatch_T regmatch; - linenr_T lnum; int maxlen = 0; size_t count = (size_t)(eap->line2 - eap->line1) + 1; size_t i; @@ -530,7 +529,7 @@ void ex_sort(exarg_T *eap) // numbers sorting it's the number to sort on. This means the pattern // matching and number conversion only has to be done once per line. // Also get the longest line length for allocating "sortbuf". - for (lnum = eap->line1; lnum <= eap->line2; lnum++) { + for (linenr_T lnum = eap->line1; lnum <= eap->line2; lnum++) { char *s = ml_get(lnum); int len = (int)strlen(s); if (maxlen < len) { @@ -622,7 +621,7 @@ void ex_sort(exarg_T *eap) bcount_t old_count = 0, new_count = 0; // Insert the lines in the sorted order below the last one. - lnum = eap->line2; + linenr_T lnum = eap->line2; for (i = 0; i < count; i++) { const linenr_T get_lnum = nrs[eap->forceit ? count - i - 1 : i].lnum; @@ -1610,7 +1609,6 @@ int do_write(exarg_T *eap) int retval = FAIL; char *free_fname = NULL; buf_T *alt_buf = NULL; - int name_was_missing; if (not_writing()) { // check 'write' option return FAIL; @@ -1742,7 +1740,7 @@ int do_write(exarg_T *eap) } } - name_was_missing = curbuf->b_ffname == NULL; + int name_was_missing = curbuf->b_ffname == NULL; retval = buf_write(curbuf, ffname, fname, eap->line1, eap->line2, eap, eap->append, eap->forceit, true, false); @@ -2108,11 +2106,9 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum bufref_T old_curbuf; char *free_fname = NULL; int retval = FAIL; - pos_T orig_pos; linenr_T topline = 0; int newcol = -1; int solcol = -1; - pos_T *pos; char *command = NULL; bool did_get_winopts = false; int readfile_flags = 0; @@ -2288,7 +2284,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum // May jump to last used line number for a loaded buffer or when asked // for explicitly if ((oldbuf && newlnum == ECMD_LASTL) || newlnum == ECMD_LAST) { - pos = &buflist_findfmark(buf)->mark; + pos_T *pos = &buflist_findfmark(buf)->mark; newlnum = pos->lnum; solcol = pos->col; } @@ -2543,7 +2539,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum // Careful: open_buffer() and apply_autocmds() may change the current // buffer and window. - orig_pos = curwin->w_cursor; + pos_T orig_pos = curwin->w_cursor; topline = curwin->w_topline; if (!oldbuf) { // need to read the file swap_exists_action = SEA_DIALOG; @@ -2892,7 +2888,7 @@ void ex_z(exarg_T *eap) { int64_t bigness; int minus = 0; - linenr_T start, end, curs, i; + linenr_T start, end, curs; linenr_T lnum = eap->line2; // Vi compatible: ":z!" uses display height, without a count uses @@ -2993,7 +2989,7 @@ void ex_z(exarg_T *eap) curs = 1; } - for (i = start; i <= end; i++) { + for (linenr_T i = start; i <= end; i++) { if (minus && i == lnum) { msg_putchar('\n'); @@ -4341,12 +4337,11 @@ void ex_global(exarg_T *eap) { linenr_T lnum; // line number according to old situation int type; // first char of cmd: 'v' or 'g' - char *cmd; // command argument + char *cmd; // command argument char delim; // delimiter, normally '/' char *pat; regmmatch_T regmatch; - int match; // When nesting the command works on one line. This allows for // ":g/found/v/notfound/command". @@ -4405,7 +4400,7 @@ void ex_global(exarg_T *eap) if (global_busy) { lnum = curwin->w_cursor.lnum; - match = vim_regexec_multi(®match, curwin, curbuf, lnum, 0, NULL, NULL); + int match = vim_regexec_multi(®match, curwin, curbuf, lnum, 0, NULL, NULL); if ((type == 'g' && match) || (type == 'v' && !match)) { global_exe_one(cmd, lnum); } @@ -4414,7 +4409,7 @@ void ex_global(exarg_T *eap) // pass 1: set marks for each (not) matching line for (lnum = eap->line1; lnum <= eap->line2 && !got_int; lnum++) { // a match on this line? - match = vim_regexec_multi(®match, curwin, curbuf, lnum, 0, NULL, NULL); + int match = vim_regexec_multi(®match, curwin, curbuf, lnum, 0, NULL, NULL); if (regmatch.regprog == NULL) { break; // re-compiling regprog failed } -- cgit From a6e3d93421ba13c407a96fac9cc01fa41ec7ad98 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 16 Nov 2023 10:59:11 +0100 Subject: refactor: enable formatting for ternaries This requires removing the "Inner expression should be aligned" rule from clint as it prevents essentially any formatting regarding ternary operators. --- src/nvim/ex_cmds.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 9a285bfe75..94fba32343 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -397,10 +397,10 @@ static int sort_compare(const void *s1, const void *s2) result = l1.st_u.num.is_number - l2.st_u.num.is_number; } else { result = l1.st_u.num.value == l2.st_u.num.value - ? 0 - : l1.st_u.num.value > l2.st_u.num.value - ? 1 - : -1; + ? 0 + : l1.st_u.num.value > l2.st_u.num.value + ? 1 + : -1; } } else if (sort_flt) { result = l1.st_u.value_flt == l2.st_u.value_flt @@ -1365,7 +1365,7 @@ char *make_filter_cmd(char *cmd, char *itmp, char *otmp) if (itmp != NULL) { len += is_pwsh ? strlen(itmp) + sizeof("& { Get-Content " " | & " " }") - 1 + 6 // +6: #20530 - : strlen(itmp) + sizeof(" { " " < " " } ") - 1; + : strlen(itmp) + sizeof(" { " " < " " } ") - 1; } if (otmp != NULL) { len += strlen(otmp) + strlen(p_srr) + 2; // two extra spaces (" "), @@ -1389,7 +1389,7 @@ char *make_filter_cmd(char *cmd, char *itmp, char *otmp) // redirecting input and/or output. if (itmp != NULL || otmp != NULL) { char *fmt = is_fish_shell ? "begin; %s; end" - : "(%s)"; + : "(%s)"; vim_snprintf(buf, len, fmt, cmd); } else { xstrlcpy(buf, cmd, len); @@ -4283,15 +4283,15 @@ bool do_sub_msg(bool count_only) } char *msg_single = count_only - ? NGETTEXT("%" PRId64 " match on %" PRId64 " line", - "%" PRId64 " matches on %" PRId64 " line", sub_nsubs) - : NGETTEXT("%" PRId64 " substitution on %" PRId64 " line", - "%" PRId64 " substitutions on %" PRId64 " line", sub_nsubs); + ? NGETTEXT("%" PRId64 " match on %" PRId64 " line", + "%" PRId64 " matches on %" PRId64 " line", sub_nsubs) + : NGETTEXT("%" PRId64 " substitution on %" PRId64 " line", + "%" PRId64 " substitutions on %" PRId64 " line", sub_nsubs); char *msg_plural = count_only - ? NGETTEXT("%" PRId64 " match on %" PRId64 " lines", - "%" PRId64 " matches on %" PRId64 " lines", sub_nsubs) - : NGETTEXT("%" PRId64 " substitution on %" PRId64 " lines", - "%" PRId64 " substitutions on %" PRId64 " lines", sub_nsubs); + ? NGETTEXT("%" PRId64 " match on %" PRId64 " lines", + "%" PRId64 " matches on %" PRId64 " lines", sub_nsubs) + : NGETTEXT("%" PRId64 " substitution on %" PRId64 " lines", + "%" PRId64 " substitutions on %" PRId64 " lines", sub_nsubs); vim_snprintf_add(msg_buf, sizeof(msg_buf), NGETTEXT(msg_single, msg_plural, sub_nlines), (int64_t)sub_nsubs, (int64_t)sub_nlines); -- cgit From ed8f9ff47bfaff99f121014c1c17ee222b4f7226 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 23 Nov 2023 16:04:45 +0800 Subject: vim-patch:8.2.2784: Vim9: cannot use \=expr in :substitute Problem: Vim9: cannot use \=expr in :substitute. Solution: Compile the expression into instructions and execute them when invoked. https://github.com/vim/vim/commit/4c13721482d7786f92f5a56e43b0f5c499264b7e Vim9 script is N/A, including substitute_instr. Co-authored-by: Bram Moolenaar --- src/nvim/ex_cmds.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 94fba32343..e3abb14481 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3222,6 +3222,25 @@ static char *sub_parse_flags(char *cmd, subflags_T *subflags, int *which_pat) return cmd; } +/// Skip over the "sub" part in :s/pat/sub/ where "delimiter" is the separating +/// character. +static char *skip_substitute(char *start, int delimiter) +{ + char *p = start; + + while (p[0]) { + if (p[0] == delimiter) { // end delimiter found + *p++ = NUL; // replace it with a NUL + break; + } + if (p[0] == '\\' && p[1] != 0) { // skip escaped characters + p++; + } + MB_PTR_ADV(p); + } + return p; +} + static int check_regexp_delim(int c) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { @@ -3349,17 +3368,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n // Small incompatibility: vi sees '\n' as end of the command, but in // Vim we want to use '\n' to find/substitute a NUL. sub = cmd; // remember the start of the substitution - - while (cmd[0]) { - if (cmd[0] == delimiter) { // end delimiter found - *cmd++ = NUL; // replace it with a NUL - break; - } - if (cmd[0] == '\\' && cmd[1] != 0) { // skip escaped characters - cmd++; - } - MB_PTR_ADV(cmd); - } + cmd = skip_substitute(cmd, delimiter); if (!eap->skip && cmdpreview_ns <= 0) { sub_set_replacement((SubReplacementString) { -- cgit From 8d8136bfcf9ea6d0b23638b48e99e09bdc8a9d44 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 23 Nov 2023 07:11:16 +0800 Subject: vim-patch:9.0.2121: [security]: use-after-free in ex_substitute Problem: [security]: use-after-free in ex_substitute Solution: always allocate memory closes: vim/vim#13552 A recursive :substitute command could cause a heap-use-after free in Vim (CVE-2023-48706). The whole reproducible test is a bit tricky, I can only reproduce this reliably when no previous substitution command has been used yet (which is the reason, the test needs to run as first one in the test_substitute.vim file) and as a combination of the `:~` command together with a :s command that contains the special substitution atom `~\=` which will make use of a sub-replace special atom and calls a vim script function. There was a comment in the existing :s code, that already makes the `sub` variable allocate memory so that a recursive :s call won't be able to cause any issues here, so this was known as a potential problem already. But for the current test-case that one does not work, because the substitution does not start with `\=` but with `~\=` (and since there does not yet exist a previous substitution atom, Vim will simply increment the `sub` pointer (which then was not allocated dynamically) and later one happily use a sub-replace special expression (which could then free the `sub` var). The following commit fixes this, by making the sub var always using allocated memory, which also means we need to free the pointer whenever we leave the function. Since sub is now always an allocated variable, we also do no longer need the sub_copy variable anymore, since this one was used to indicated when sub pointed to allocated memory (and had therefore to be freed on exit) and when not. Github Security Advisory: https://github.com/vim/vim/security/advisories/GHSA-c8qm-x72m-q53q https://github.com/vim/vim/commit/26c11c56888d01e298cd8044caf860f3c26f57bb Co-authored-by: Christian Brabandt --- src/nvim/ex_cmds.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index e3abb14481..c406364491 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3367,8 +3367,9 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n // Small incompatibility: vi sees '\n' as end of the command, but in // Vim we want to use '\n' to find/substitute a NUL. - sub = cmd; // remember the start of the substitution + char *p = cmd; // remember the start of the substitution cmd = skip_substitute(cmd, delimiter); + sub = xstrdup(p); if (!eap->skip && cmdpreview_ns <= 0) { sub_set_replacement((SubReplacementString) { @@ -3383,7 +3384,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n return 0; } pat = NULL; // search_regcomp() will use previous pattern - sub = old_sub.sub; + sub = xstrdup(old_sub.sub); // Vi compatibility quirk: repeating with ":s" keeps the cursor in the // last column after using "$". @@ -3391,6 +3392,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n } if (sub != NULL && sub_joining_lines(eap, pat, sub, cmd, cmdpreview_ns <= 0)) { + xfree(sub); return 0; } @@ -3405,11 +3407,13 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n i = getdigits_int(&cmd, true, INT_MAX); if (i <= 0 && !eap->skip && subflags.do_error) { emsg(_(e_zerocount)); + xfree(sub); return 0; } else if (i >= INT_MAX) { char buf[20]; vim_snprintf(buf, sizeof(buf), "%d", i); semsg(_(e_val_too_large), buf); + xfree(sub); return 0; } eap->line1 = eap->line2; @@ -3425,17 +3429,20 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n eap->nextcmd = check_nextcmd(cmd); if (eap->nextcmd == NULL) { semsg(_(e_trailing_arg), cmd); + xfree(sub); return 0; } } if (eap->skip) { // not executing commands, only parsing + xfree(sub); return 0; } if (!subflags.do_count && !MODIFIABLE(curbuf)) { // Substitution is not allowed in non-'modifiable' buffer emsg(_(e_modifiable)); + xfree(sub); return 0; } @@ -3444,6 +3451,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n if (subflags.do_error) { emsg(_(e_invcmd)); } + xfree(sub); return 0; } @@ -3458,22 +3466,20 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n assert(sub != NULL); - char *sub_copy = NULL; - // If the substitute pattern starts with "\=" then it's an expression. // Make a copy, a recursive function may free it. // Otherwise, '~' in the substitute pattern is replaced with the old // pattern. We do it here once to avoid it to be replaced over and over // again. if (sub[0] == '\\' && sub[1] == '=') { - sub = xstrdup(sub); - sub_copy = sub; + char *p = xstrdup(sub); + xfree(sub); + sub = p; } else { - char *newsub = regtilde(sub, magic_isset(), cmdpreview_ns > 0); - if (newsub != sub) { - // newsub was allocated, free it later. - sub_copy = newsub; - sub = newsub; + char *p = regtilde(sub, magic_isset(), cmdpreview_ns > 0); + if (p != sub) { + xfree(sub); + sub = p; } } @@ -4244,7 +4250,7 @@ skip: } vim_regfree(regmatch.regprog); - xfree(sub_copy); + xfree(sub); // Restore the flag values, they can be used for ":&&". subflags.do_all = save_do_all; -- cgit From a827003e3052c6d9ee7bdb71518182e9bd76317d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 25 Nov 2023 11:32:32 +0100 Subject: build: rework IWYU mapping files Create mapping to most of the C spec and some POSIX specific functions. This is more robust than relying files shipped with IWYU. --- src/nvim/ex_cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index c406364491..324364a297 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,6 @@ #include "nvim/getchar.h" #include "nvim/gettext.h" #include "nvim/globals.h" -#include "nvim/grid_defs.h" #include "nvim/help.h" #include "nvim/highlight_defs.h" #include "nvim/highlight_group.h" -- cgit From a917da4ca55be8726f26a8305c53bdd5b2c7eea4 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 26 Nov 2023 21:53:07 +0100 Subject: refactor(encoding): remove redundant vim_isprintc_strict This function is identical to vim_isprintc when encoding=utf-8 is used As this is the only internal encoding nvim supports, it is now redundant ref #2905 --- src/nvim/ex_cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 324364a297..8378c04197 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -155,7 +155,7 @@ void do_ascii(exarg_T *eap) ? NL // NL is stored as CR. : c); char buf1[20]; - if (vim_isprintc_strict(c) && (c < ' ' || c > '~')) { + if (vim_isprintc(c) && (c < ' ' || c > '~')) { char buf3[7]; transchar_nonprint(curbuf, buf3, c); vim_snprintf(buf1, sizeof(buf1), " <%s>", buf3); -- cgit From 574d25642fc9ca65b396633aeab6e2d32778b642 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Nov 2023 17:21:58 +0800 Subject: refactor: move Arena and ArenaMem to memory_defs.h (#26240) --- src/nvim/ex_cmds.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 8378c04197..267137cd0a 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -25,7 +25,6 @@ #include "nvim/change.h" #include "nvim/channel.h" #include "nvim/charset.h" -#include "nvim/cmdexpand_defs.h" #include "nvim/cmdhist.h" #include "nvim/cursor.h" #include "nvim/decoration.h" -- cgit From 38a20dd89f91c45ec8589bf1c50d50732882d38a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Nov 2023 20:58:37 +0800 Subject: build(IWYU): replace most private mappings with pragmas (#26247) --- src/nvim/ex_cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 267137cd0a..d77bd47fcf 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -65,7 +65,7 @@ #include "nvim/option.h" #include "nvim/option_vars.h" #include "nvim/optionstr.h" -#include "nvim/os/fs_defs.h" +#include "nvim/os/fs.h" #include "nvim/os/input.h" #include "nvim/os/os.h" #include "nvim/os/shell.h" -- cgit From 8b428ca8b79ebb7b36c3e403ff3bcb6924a635a6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 16:00:21 +0100 Subject: build(IWYU): fix includes for func_attr.h --- src/nvim/ex_cmds.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index d77bd47fcf..996d88e1f8 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -43,6 +43,7 @@ #include "nvim/extmark.h" #include "nvim/fileio.h" #include "nvim/fold.h" +#include "nvim/func_attr.h" #include "nvim/getchar.h" #include "nvim/gettext.h" #include "nvim/globals.h" -- cgit From f4aedbae4cb1f206f5b7c6142697b71dd473059b Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 18:39:38 +0100 Subject: build(IWYU): fix includes for undo_defs.h --- src/nvim/ex_cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 996d88e1f8..802a688ed0 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -73,7 +73,7 @@ #include "nvim/os/time.h" #include "nvim/path.h" #include "nvim/plines.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/profile.h" #include "nvim/quickfix.h" #include "nvim/regexp.h" -- cgit From 6c14ae6bfaf51415b555e9a6b85d1d280976358d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:27:32 +0100 Subject: refactor: rename types.h to types_defs.h --- src/nvim/ex_cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 802a688ed0..a11d3f0bca 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -81,7 +81,7 @@ #include "nvim/spell.h" #include "nvim/strings.h" #include "nvim/terminal.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/vim.h" -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/ex_cmds.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index a11d3f0bca..974631d61f 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -16,7 +16,7 @@ #include "auto/config.h" #include "klib/kvec.h" #include "nvim/arglist.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/autocmd.h" #include "nvim/buffer.h" #include "nvim/buffer_defs.h" @@ -52,7 +52,7 @@ #include "nvim/highlight_group.h" #include "nvim/indent.h" #include "nvim/input.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/main.h" #include "nvim/mark.h" #include "nvim/mbyte.h" @@ -84,7 +84,7 @@ #include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/undo.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #include "nvim/window.h" /// Case matching style to use for :substitute -- cgit From a6cba103cebce535279db197f9efeb34e9d1171f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 20:32:40 +0800 Subject: refactor: move some constants out of vim_defs.h (#26298) --- src/nvim/ex_cmds.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds.c') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 974631d61f..e369397047 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -48,7 +48,7 @@ #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/help.h" -#include "nvim/highlight_defs.h" +#include "nvim/highlight.h" #include "nvim/highlight_group.h" #include "nvim/indent.h" #include "nvim/input.h" @@ -79,6 +79,7 @@ #include "nvim/regexp.h" #include "nvim/search.h" #include "nvim/spell.h" +#include "nvim/state_defs.h" #include "nvim/strings.h" #include "nvim/terminal.h" #include "nvim/types_defs.h" -- cgit