From 33952a7661927f875ebf40a60e236831c789de58 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 18:53:02 +0300 Subject: [PATCH 01/53] *: Silence some false positives --- src/nvim/api/private/helpers.h | 1 + src/nvim/buffer.h | 3 ++- src/nvim/eval/typval_encode.c.h | 4 ++-- src/nvim/globals.h | 1 + 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 9fe8c351cf..20b4015fb5 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -8,6 +8,7 @@ #include "nvim/memory.h" #include "nvim/lib/kvec.h" +// -V:api_set_error:618 #define api_set_error(err, errtype, ...) \ do { \ snprintf((err)->msg, \ diff --git a/src/nvim/buffer.h b/src/nvim/buffer.h index 016c5ce3b7..39b9faf8b1 100644 --- a/src/nvim/buffer.h +++ b/src/nvim/buffer.h @@ -103,7 +103,8 @@ static inline void buf_set_changedtick(buf_T *const buf, const int changedtick) assert(changedtick_di->di_flags == (DI_FLAGS_RO|DI_FLAGS_FIX)); # endif assert(changedtick_di == (dictitem_T *)&buf->changedtick_di); - assert(&buf->b_changedtick == &buf->changedtick_di.di_tv.vval.v_number); + assert(&buf->b_changedtick // -V501 + == &buf->changedtick_di.di_tv.vval.v_number); #endif buf->b_changedtick = changedtick; } diff --git a/src/nvim/eval/typval_encode.c.h b/src/nvim/eval/typval_encode.c.h index ad54eef4a0..3487880bd2 100644 --- a/src/nvim/eval/typval_encode.c.h +++ b/src/nvim/eval/typval_encode.c.h @@ -611,7 +611,7 @@ _convert_one_value_regular_dict: {} typval_encode_stop_converting_one_item: return OK; // Prevent “unused label” warnings. - goto typval_encode_stop_converting_one_item; + goto typval_encode_stop_converting_one_item; // -V779 } TYPVAL_ENCODE_SCOPE int _TYPVAL_ENCODE_ENCODE( @@ -814,6 +814,6 @@ encode_vim_to__error_ret: _mp_destroy(mpstack); return FAIL; // Prevent “unused label” warnings. - goto typval_encode_stop_converting_one_item; + goto typval_encode_stop_converting_one_item; // -V779 } #endif // NVIM_EVAL_TYPVAL_ENCODE_C_H diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 3c705d88a5..df9f418951 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -548,6 +548,7 @@ EXTERN win_T *prevwin INIT(= NULL); /* previous window */ FOR_ALL_TABS(tp) \ FOR_ALL_WINDOWS_IN_TAB(wp, tp) +// -V:FOR_ALL_WINDOWS_IN_TAB:501 # define FOR_ALL_WINDOWS_IN_TAB(wp, tp) \ for (win_T *wp = ((tp) == curtab) \ ? firstwin : (tp)->tp_firstwin; wp != NULL; wp = wp->w_next) From a096766ee3edc1197039d236c3a5c42365d60d4d Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 19:27:17 +0300 Subject: [PATCH 02/53] diff: Silence -V519 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not exactly a false positive, but previous assignment is a part of the pattern “change global, run code which uses it, change global back”. --- src/nvim/diff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nvim/diff.c b/src/nvim/diff.c index ff76abc01f..49574fbbfc 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1076,8 +1076,8 @@ void diff_win_options(win_T *wp, int addbuf) if (!wp->w_p_diff) { wp->w_p_wrap_save = wp->w_p_wrap; } - wp->w_p_wrap = FALSE; - curwin = wp; + wp->w_p_wrap = false; + curwin = wp; // -V519 curbuf = curwin->w_buffer; if (!wp->w_p_diff) { From 2901921a1b5bf72cb404fed0ed0510124eaf6e8b Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 19:30:18 +0300 Subject: [PATCH 03/53] digraph: Ignore false positive Reversed order is intentional, digraphs allow swapping characters. --- src/nvim/digraph.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 560205fe7d..fb4a8c6d0d 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1569,7 +1569,8 @@ int getdigraph(int char1, int char2, int meta_char) if (((retval = getexactdigraph(char1, char2, meta_char)) == char2) && (char1 != char2) - && ((retval = getexactdigraph(char2, char1, meta_char)) == char1)) { + && ((retval = getexactdigraph(char2, char1, meta_char)) // -V764 + == char1)) { return char2; } return retval; From 4f0fc1f06a6b551c081f1e4abf1a119588c6a386 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 19:32:38 +0300 Subject: [PATCH 04/53] digraph: Fix errors due to has_mbyte and friends being fixed --- src/nvim/digraph.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index fb4a8c6d0d..66fb525920 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1676,11 +1676,7 @@ static void printdigraph(digr_T *dp) int list_width; - if ((dy_flags & DY_UHEX) || has_mbyte) { - list_width = 13; - } else { - list_width = 11; - } + list_width = 13; if (dp->result != 0) { if (msg_col > Columns - list_width) { @@ -1701,15 +1697,11 @@ static void printdigraph(digr_T *dp) *p++ = dp->char2; *p++ = ' '; - if (has_mbyte) { - // add a space to draw a composing char on - if (enc_utf8 && utf_iscomposing(dp->result)) { - *p++ = ' '; - } - p += (*mb_char2bytes)(dp->result, p); - } else { - *p++ = (char_u)dp->result; + // add a space to draw a composing char on + if (utf_iscomposing(dp->result)) { + *p++ = ' '; } + p += (*mb_char2bytes)(dp->result, p); if (char2cells(dp->result) == 1) { *p++ = ' '; From 9e9ba14e0e443beff4c1418cdaff412c394852c0 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 19:38:16 +0300 Subject: [PATCH 05/53] edit: Fix strange code Based on the flow it looks like ptr could not be NULL here: if ptr_arg is NULL ptr is compl_leader, if compl_leader is NULL function exits. This also applies to Vim as far as I see. --- src/nvim/edit.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/nvim/edit.c b/src/nvim/edit.c index fe00027dec..1ca5424736 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -3427,10 +3427,11 @@ static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg) len -= (*mb_head_off)(p, p + len); for (p += len; *p != NUL; mb_ptr_adv(p)) AppendCharToRedobuff(K_BS); - } else + } else { len = 0; - if (ptr != NULL) - AppendToRedobuffLit(ptr + len, -1); + } + assert(ptr != NULL); + AppendToRedobuffLit(ptr + len, -1); } /* From fb4754104b50baa0eb489e5c9b50c1d37523f2d3 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 19:39:55 +0300 Subject: [PATCH 06/53] macros: Fix excessive check --- src/nvim/macros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/macros.h b/src/nvim/macros.h index b816b34b39..214af82422 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -75,7 +75,7 @@ do { \ if (*p_langmap \ && (condition) \ - && (p_lrm || (!p_lrm && KeyTyped)) \ + && (p_lrm || KeyTyped) \ && !KeyStuffed \ && (c) >= 0) \ { \ From dd5b0cc17a1ec6925c6cd7a5be23eb78bf953f76 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 19:50:23 +0300 Subject: [PATCH 07/53] edit: Copy assert to before the warning --- src/nvim/edit.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 1ca5424736..51d0847bc7 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -3419,6 +3419,7 @@ static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg) else return; /* nothing to do */ } + assert(ptr != NULL); if (compl_orig_text != NULL) { p = compl_orig_text; for (len = 0; p[len] != NUL && p[len] == ptr[len]; ++len) From d70a0f6895048a3dcb5ec841afd01daee4866be4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 19:51:35 +0300 Subject: [PATCH 08/53] eval/typval_encode: Silence then/else equivalence warning --- src/nvim/eval/typval_encode.c.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/eval/typval_encode.c.h b/src/nvim/eval/typval_encode.c.h index 3487880bd2..b4a70fb188 100644 --- a/src/nvim/eval/typval_encode.c.h +++ b/src/nvim/eval/typval_encode.c.h @@ -489,7 +489,7 @@ static int _TYPVAL_ENCODE_CONVERT_ONE_VALUE( } if (is_string) { TYPVAL_ENCODE_CONV_STR_STRING(tv, buf, len); - } else { + } else { // -V523 TYPVAL_ENCODE_CONV_STRING(tv, buf, len); } xfree(buf); From 05c1829a8ccf2df07927bec502467faa443d90d8 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 19:55:49 +0300 Subject: [PATCH 09/53] eval: Silence eap->skip false positives `lnum` starts at `eap->line2` in case of skipping, so cycle is always run at least once. --- src/nvim/eval.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 772994de31..49e3590185 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2747,7 +2747,7 @@ void ex_call(exarg_T *eap) } else lnum = eap->line1; for (; lnum <= eap->line2; ++lnum) { - if (!eap->skip && eap->addr_count > 0) { + if (!eap->skip && eap->addr_count > 0) { // -V560 curwin->w_cursor.lnum = lnum; curwin->w_cursor.col = 0; curwin->w_cursor.coladd = 0; @@ -2768,7 +2768,7 @@ void ex_call(exarg_T *eap) } tv_clear(&rettv); - if (doesrange || eap->skip) { + if (doesrange || eap->skip) { // -V560 break; } From 97a1ccf8e7470d8c781c86253f8a7795fe50dc50 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 19:56:55 +0300 Subject: [PATCH 10/53] eval: Fix V547: `d == NULL` was already checked at line 2986 --- src/nvim/eval.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 49e3590185..4cc400799d 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2999,8 +2999,7 @@ int do_unlet(const char *const name, const size_t name_len, const int forceit) return FAIL; } - if (d == NULL - || tv_check_lock(d->dv_lock, (const char *)name, STRLEN(name))) { + if (tv_check_lock(d->dv_lock, (const char *)name, STRLEN(name))) { return FAIL; } From 7c9e3d6cadb441aaa40c8539de41e302228196a9 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:02:06 +0300 Subject: [PATCH 11/53] eval: Refactor f_char2nr With has_mbyte equal to 1 and &encoding always UTF-8 second argument is no longer useful: utf_ptr2char is the same as mb_ptr2char. Also changes function behaviour a bit: now if second argument is not a number it immediately returns with error, without bothering to get a character. --- src/nvim/eval.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 4cc400799d..bfc9f6eaa6 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -7305,18 +7305,14 @@ static void f_changenr(typval_T *argvars, typval_T *rettv, FunPtr fptr) */ static void f_char2nr(typval_T *argvars, typval_T *rettv, FunPtr fptr) { - if (has_mbyte) { - int utf8 = 0; - - if (argvars[1].v_type != VAR_UNKNOWN) { - utf8 = tv_get_number_chk(&argvars[1], NULL); + if (argvars[1].v_type != VAR_UNKNOWN) { + if (!tv_check_num(&argvars[1])) { + return; } - - rettv->vval.v_number = (utf8 ? *utf_ptr2char : *mb_ptr2char)( - (const char_u *)tv_get_string(&argvars[0])); - } else { - rettv->vval.v_number = (uint8_t)(tv_get_string(&argvars[0])[0]); } + + rettv->vval.v_number = utf_ptr2char( + (const char_u *)tv_get_string(&argvars[0])); } /* From 31190879cc85cb3e8a056d544ea0c3ed63ce21df Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:07:54 +0300 Subject: [PATCH 12/53] eval: Fix useless NULL check partial_name() as it is written now really cannot return NULL --- src/nvim/eval.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index bfc9f6eaa6..f8afc03c1c 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -8977,13 +8977,10 @@ static void f_get(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (strcmp(what, "func") == 0 || strcmp(what, "name") == 0) { rettv->v_type = (*what == 'f' ? VAR_FUNC : VAR_STRING); const char *const n = (const char *)partial_name(pt); - if (n == NULL) { - rettv->vval.v_string = NULL; - } else { - rettv->vval.v_string = (char_u *)xstrdup(n); - if (rettv->v_type == VAR_FUNC) { - func_ref(rettv->vval.v_string); - } + assert(n != NULL); + rettv->vval.v_string = (char_u *)xstrdup(n); + if (rettv->v_type == VAR_FUNC) { + func_ref(rettv->vval.v_string); } } else if (strcmp(what, "dict") == 0) { rettv->v_type = VAR_DICT; From 3c5f4b382f62d9f3cf5d54720592ff75d3a1f86d Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:08:56 +0300 Subject: [PATCH 13/53] eval: Silence octal constant warning --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index f8afc03c1c..a259bbf0eb 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -12538,7 +12538,7 @@ static void f_min(typval_T *argvars, typval_T *rettv, FunPtr fptr) */ static void f_mkdir(typval_T *argvars, typval_T *rettv, FunPtr fptr) { - int prot = 0755; + int prot = 0755; // -V536 rettv->vval.v_number = FAIL; if (check_restricted() || check_secure()) From fbdef2e6f2d65d3cc6f3c8a8dcd8b3cddf41c474 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:16:32 +0300 Subject: [PATCH 14/53] eval: Refactor nr2char() Adds error messages, checks type and ignores the second argument. Currently utf_char2bytes is able to handle any 31-bit character, not limited by a unicode range. So checking for INT_MAX and not for something else: function yet uses `int`. --- src/nvim/eval.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index a259bbf0eb..71af801986 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -12763,25 +12763,32 @@ static void f_nextnonblank(typval_T *argvars, typval_T *rettv, FunPtr fptr) */ static void f_nr2char(typval_T *argvars, typval_T *rettv, FunPtr fptr) { - char_u buf[NUMBUFLEN]; - - if (has_mbyte) { - int utf8 = 0; - - if (argvars[1].v_type != VAR_UNKNOWN) { - utf8 = tv_get_number_chk(&argvars[1], NULL); + if (argvars[1].v_type != VAR_UNKNOWN) { + if (!tv_check_num(&argvars[1])) { + return; } - if (utf8) { - buf[(*utf_char2bytes)((int)tv_get_number(&argvars[0]), buf)] = NUL; - } else { - buf[(*mb_char2bytes)((int)tv_get_number(&argvars[0]), buf)] = NUL; - } - } else { - buf[0] = (char_u)tv_get_number(&argvars[0]); - buf[1] = NUL; } + + bool error = false; + const varnumber_T num = tv_get_number_chk(&argvars[0], &error); + if (error) { + return; + } + if (num < 0) { + emsgf(_("E5070: Character number could not be less then zero")); + return; + } + if (num > INT_MAX) { + emsgf(_("E5071: Character number could not be greater then INT_MAX (%i)"), + INT_MAX); + return; + } + + char buf[MB_MAXBYTES]; + const int len = utf_char2bytes((int)num, (char_u *)buf); + rettv->v_type = VAR_STRING; - rettv->vval.v_string = vim_strsave(buf); + rettv->vval.v_string = xmemdupz(buf, (size_t)len); } /* From 787d71a3afbe619a301ba7898e2c43fdcffdc8ec Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:19:10 +0300 Subject: [PATCH 15/53] eval: Fix condition in f_serverstop --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 71af801986..2a725c49f7 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -14306,7 +14306,7 @@ static void f_serverstop(typval_T *argvars, typval_T *rettv, FunPtr fptr) return; } - if (argvars[0].v_type == VAR_UNKNOWN || argvars[0].v_type != VAR_STRING) { + if (argvars[0].v_type != VAR_STRING) { EMSG(_(e_invarg)); return; } From 9b1dd084257fc2b5f50e29b283be698c13d4a509 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:20:38 +0300 Subject: [PATCH 16/53] eval: Remove unneeded varp check --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 2a725c49f7..6e204be481 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -14330,7 +14330,7 @@ static void f_setbufvar(typval_T *argvars, typval_T *rettv, FunPtr fptr) buf_T *const buf = get_buf_tv(&argvars[0], false); typval_T *varp = &argvars[2]; - if (buf != NULL && varname != NULL && varp != NULL) { + if (buf != NULL && varname != NULL) { if (*varname == '&') { long numval; bool error = false; From 9dd1926df01a27c913dd19ef0a4f79d06842508a Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:20:53 +0300 Subject: [PATCH 17/53] eval: Remove unneeded varp check --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 6e204be481..30b776c887 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -14874,7 +14874,7 @@ static void f_settabvar(typval_T *argvars, typval_T *rettv, FunPtr fptr) const char *const varname = tv_get_string_chk(&argvars[1]); typval_T *const varp = &argvars[2]; - if (varname != NULL && varp != NULL && tp != NULL) { + if (varname != NULL && tp != NULL) { tabpage_T *const save_curtab = curtab; goto_tabpage_tp(tp, false, false); From 1bc080078793aafcecfae95620f6dac917c737dc Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:22:12 +0300 Subject: [PATCH 18/53] eval: Remove unneeded !eap->skip check Already checked in the outer if(). --- src/nvim/eval.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 30b776c887..67d5465896 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -19462,8 +19462,9 @@ void ex_function(exarg_T *eap) * interrupt, or an exception. */ if (!aborting()) { - if (!eap->skip && fudi.fd_newkey != NULL) + if (fudi.fd_newkey != NULL) { EMSG2(_(e_dictkey), fudi.fd_newkey); + } xfree(fudi.fd_newkey); return; } else From c5010c98ae8532f7f2778ce0e89a01d9e1ca68f9 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:22:58 +0300 Subject: [PATCH 19/53] eval: Fix position of buf declaration --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 67d5465896..cf55b42bdf 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -21048,8 +21048,8 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, char *s = tofree; emsg_off--; if (s != NULL) { + char buf[MSG_BUF_LEN]; if (vim_strsize((char_u *)s) > MSG_BUF_CLEN) { - char buf[MSG_BUF_LEN]; trunc_string((char_u *)s, (char_u *)buf, MSG_BUF_CLEN, sizeof(buf)); s = buf; From d766607dc9e3c54a7575102ecf025eb184d9f648 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:24:30 +0300 Subject: [PATCH 20/53] farsi: Simplify condition --- src/nvim/farsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/farsi.c b/src/nvim/farsi.c index e7e93f756f..2d37d1284e 100644 --- a/src/nvim/farsi.c +++ b/src/nvim/farsi.c @@ -321,7 +321,7 @@ static void put_curr_and_l_to_X(char_u c) } if ((curwin->w_cursor.col < (colnr_T)STRLEN(get_cursor_line_ptr()))) { - if ((p_ri && curwin->w_cursor.col) || !p_ri) { + if (!p_ri || curwin->w_cursor.col) { if (p_ri) { dec_cursor(); } else { From a894c82defc00fcd0ed14a6d157130d9dc63f314 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:25:00 +0300 Subject: [PATCH 21/53] ex_docmd: Remove excessive assignment --- src/nvim/ex_docmd.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 0fd4ae48be..3d1136b7ac 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -1304,7 +1304,6 @@ static char_u * do_one_cmd(char_u **cmdlinep, /* * 2. Handle command modifiers. */ - p = ea.cmd; p = skip_range(ea.cmd, NULL); switch (*p) { /* When adding an entry, also modify cmd_exists(). */ From 87e107d92143e108ec3ec5f91851ca3cb3768175 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:27:20 +0300 Subject: [PATCH 22/53] ex_docmd: Remove :Ni! easter egg --- src/nvim/ex_docmd.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 3d1136b7ac..60d3bb07a3 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -1726,11 +1726,7 @@ static char_u * do_one_cmd(char_u **cmdlinep, errormsg = (char_u *)_("E464: Ambiguous use of user-defined command"); goto doend; } - /* Check for wrong commands. */ - if (*p == '!' && ea.cmd[1] == 0151 && ea.cmd[0] == 78) { - errormsg = uc_fun_cmd(); - goto doend; - } + // Check for wrong commands. if (ea.cmdidx == CMD_SIZE) { if (!ea.skip) { STRCPY(IObuff, _("E492: Not an editor command")); @@ -4961,20 +4957,6 @@ static void uc_list(char_u *name, size_t name_len) MSG(_("No user-defined commands found")); } -static char_u *uc_fun_cmd(void) -{ - static char_u fcmd[] = {0x84, 0xaf, 0x60, 0xb9, 0xaf, 0xb5, 0x60, 0xa4, - 0xa5, 0xad, 0xa1, 0xae, 0xa4, 0x60, 0xa1, 0x60, - 0xb3, 0xa8, 0xb2, 0xb5, 0xa2, 0xa2, 0xa5, 0xb2, - 0xb9, 0x7f, 0}; - int i; - - for (i = 0; fcmd[i]; ++i) - IObuff[i] = fcmd[i] - 0x40; - IObuff[i] = 0; - return IObuff; -} - static int uc_scan_attr(char_u *attr, size_t len, uint32_t *argt, long *def, int *flags, int * compl, char_u **compl_arg, int *addr_type_arg) From fe01e9c947b8c2fcb328e79b8b91ceebfd8c04cc Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:27:47 +0300 Subject: [PATCH 23/53] ex_docmd: Remove unneeded if() --- src/nvim/ex_docmd.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 60d3bb07a3..0e399c9fb3 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -4097,12 +4097,11 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp) options += WILD_ICASE; p = ExpandOne(&xpc, eap->arg, NULL, options, WILD_EXPAND_FREE); - if (p == NULL) + if (p == NULL) { return FAIL; - if (p != NULL) { - (void)repl_cmdline(eap, eap->arg, STRLEN(eap->arg), p, cmdlinep); - xfree(p); } + (void)repl_cmdline(eap, eap->arg, STRLEN(eap->arg), p, cmdlinep); + xfree(p); } } return OK; From d88ae748b51963d0188fe41f0abd6ea208bd2eef Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:29:19 +0300 Subject: [PATCH 24/53] getchar: Fix if block indentation --- src/nvim/getchar.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 3b248c4bc6..e056ff488c 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1849,11 +1849,12 @@ static int vgetorpeek(int advance) mp_match = mp; mp_match_len = keylen; } - } else - /* No match; may have to check for - * termcode at next character. */ - if (max_mlen < mlen) - max_mlen = mlen; + } else { + // No match; may have to check for termcode at next character. + if (max_mlen < mlen) { + max_mlen = mlen; + } + } } } From e3de83a8291cf0ef1481a2631dda04b37b6e3412 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:32:10 +0300 Subject: [PATCH 25/53] hardcopy: Remove unneeded prt_do_conv assignment --- src/nvim/hardcopy.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 4cb05ffc12..b2cbe30a43 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -2576,13 +2576,12 @@ int mch_print_begin(prt_settings_T *psettings) prt_conv.vc_type = CONV_NONE; if (!(enc_canon_props(p_enc) & enc_canon_props(p_encoding) & ENC_8BIT)) { - /* Set up encoding conversion if required */ - if (FAIL == convert_setup(&prt_conv, p_enc, p_encoding)) { - EMSG2(_("E620: Unable to convert to print encoding \"%s\""), - p_encoding); - return FALSE; + // Set up encoding conversion if required + if (convert_setup(&prt_conv, p_enc, p_encoding) == FAIL) { + emsgf(_("E620: Unable to convert to print encoding \"%s\""), + p_encoding); + return false; } - prt_do_conv = TRUE; } prt_do_conv = prt_conv.vc_type != CONV_NONE; From 0f7c260cd873c996da9badb42b9135cd15bee285 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:39:57 +0300 Subject: [PATCH 26/53] fileio: Simlify help files encoding detection Most of code is dead when enc_utf8 is always true. Given that `c` is being reused for other purposes I left it set to 1 just in case. --- src/nvim/fileio.c | 43 ++++++++----------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index c1b8203ed1..74fa5aa1de 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -730,43 +730,16 @@ readfile ( fenc = (char_u *)""; /* binary: don't convert */ fenc_alloced = FALSE; } else if (curbuf->b_help) { - char_u firstline[80]; - int fc; + // Help files are either utf-8 or latin1. Try utf-8 first, if this + // fails it must be latin1. + // It is needed when the first line contains non-ASCII characters. + // That is only in *.??x files. + fenc_next = (char_u *)"latin1"; + fenc = (char_u *)"utf-8"; - /* Help files are either utf-8 or latin1. Try utf-8 first, if this - * fails it must be latin1. - * Always do this when 'encoding' is "utf-8". Otherwise only do - * this when needed to avoid [converted] remarks all the time. - * It is needed when the first line contains non-ASCII characters. - * That is only in *.??x files. */ - fenc = (char_u *)"latin1"; - c = enc_utf8; - if (!c && !read_stdin) { - fc = fname[STRLEN(fname) - 1]; - if (TOLOWER_ASC(fc) == 'x') { - /* Read the first line (and a bit more). Immediately rewind to - * the start of the file. If the read() fails "len" is -1. */ - len = read_eintr(fd, firstline, 80); - lseek(fd, (off_t)0L, SEEK_SET); - for (p = firstline; p < firstline + len; ++p) - if (*p >= 0x80) { - c = TRUE; - break; - } - } - } + fenc_alloced = false; - if (c) { - fenc_next = fenc; - fenc = (char_u *)"utf-8"; - - /* When the file is utf-8 but a character doesn't fit in - * 'encoding' don't retry. In help text editing utf-8 bytes - * doesn't make sense. */ - if (!enc_utf8) - keep_dest_enc = TRUE; - } - fenc_alloced = FALSE; + c = 1; } else if (*p_fencs == NUL) { fenc = curbuf->b_p_fenc; /* use format from buffer */ fenc_alloced = FALSE; From 2394c9f2b79e5c9c121c21dcb324f9c18b473853 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:47:06 +0300 Subject: [PATCH 27/53] =?UTF-8?q?memline:=20Silence=20=E2=80=9Cbuffer=20un?= =?UTF-8?q?derflow=E2=80=9D=20warning,=20looks=20like=20false=20positive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/nvim/memline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 5ea2397db3..45e16554e6 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -616,7 +616,7 @@ static bool ml_check_b0_strings(ZERO_BL *b0p) return (memchr(b0p->b0_version, NUL, 10) && memchr(b0p->b0_uname, NUL, B0_UNAME_SIZE) && memchr(b0p->b0_hname, NUL, B0_HNAME_SIZE) - && memchr(b0p->b0_fname, NUL, B0_FNAME_SIZE_CRYPT)); + && memchr(b0p->b0_fname, NUL, B0_FNAME_SIZE_CRYPT)); // -V512 } /* From 10ce00efa8c9d4e9f2b588063ce04f7d49050d8b Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:55:29 +0300 Subject: [PATCH 28/53] =?UTF-8?q?memline:=20Fix=20=E2=80=9CNULL=20pointer?= =?UTF-8?q?=20dereference=E2=80=9D=20warning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was actually a false positive indicating always-true condition, not real dereference. --- src/nvim/memline.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 45e16554e6..b31ca136dd 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -3362,29 +3362,32 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, } if (swap_exists_action != SEA_NONE && choice == 0) { - char *name; + const char *const sw_msg_1 = _("Swap file \""); + const char *const sw_msg_2 = _("\" already exists!"); const size_t fname_len = strlen(fname); - name = xmalloc(fname_len - + strlen(_("Swap file \"")) - + strlen(_("\" already exists!")) + 5); - STRCPY(name, _("Swap file \"")); - home_replace(NULL, (char_u *) fname, (char_u *)&name[strlen(name)], - fname_len, true); - STRCAT(name, _("\" already exists!")); - choice = do_dialog(VIM_WARNING, - (char_u *)_("VIM - ATTENTION"), - (char_u *)(name == NULL - ? _("Swap file already exists!") - : name), + const size_t sw_msg_1_len = strlen(sw_msg_1); + const size_t sw_msg_2_len = strlen(sw_msg_2); + + const size_t name_len = sw_msg_1_len + fname_len + sw_msg_2_len + 5; + + char *const name = xmalloc(name_len); + memcpy(name, sw_msg_1, sw_msg_1_len + 1); + home_replace(NULL, (char_u *)fname, (char_u *)&name[sw_msg_1_len], + fname_len, true); + xstrlcat(name, sw_msg_2, name_len); + choice = do_dialog(VIM_WARNING, (char_u *)_("VIM - ATTENTION"), + (char_u *)name, # if defined(UNIX) - process_still_running - ? (char_u *)_( - "&Open Read-Only\n&Edit anyway\n&Recover\n&Quit\n&Abort") : + process_still_running + ? (char_u *)_( + "&Open Read-Only\n&Edit anyway\n&Recover" + "\n&Quit\n&Abort") : # endif - (char_u *)_( - "&Open Read-Only\n&Edit anyway\n&Recover\n&Delete it\n&Quit\n&Abort"), - 1, NULL, FALSE); + (char_u *)_( + "&Open Read-Only\n&Edit anyway\n&Recover" + "\n&Delete it\n&Quit\n&Abort"), + 1, NULL, false); # if defined(UNIX) if (process_still_running && choice >= 4) From 083792e1374100f1b0c48c72987935f56ebbd8ad Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:56:30 +0300 Subject: [PATCH 29/53] =?UTF-8?q?message:=20Remove=20some=20enc=5Futf8/?= =?UTF-8?q?=E2=80=A6=20checks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/nvim/message.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/nvim/message.c b/src/nvim/message.c index 3e4a1e10b6..91dfc79e38 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -1165,15 +1165,9 @@ int msg_outtrans_len_attr(char_u *msgstr, int len, int attr) * Normal characters are printed several at a time. */ while (--len >= 0) { - if (enc_utf8) { - // Don't include composing chars after the end. - mb_l = utfc_ptr2len_len((char_u *)str, len + 1); - } else if (has_mbyte) { - mb_l = (*mb_ptr2len)((char_u *)str); - } else { - mb_l = 1; - } - if (has_mbyte && mb_l > 1) { + // Don't include composing chars after the end. + mb_l = utfc_ptr2len_len((char_u *)str, len + 1); + if (mb_l > 1) { c = (*mb_ptr2char)((char_u *)str); if (vim_isprintc(c)) { // Printable multi-byte char: count the cells. From 0718d0e6d44536547dac2248c65b15547e56fc10 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:58:19 +0300 Subject: [PATCH 30/53] message: Some more has_mbyte/enc_utf8 removal --- src/nvim/message.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/nvim/message.c b/src/nvim/message.c index 91dfc79e38..42e1fd1cf9 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -1657,16 +1657,13 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, // Display char in last column before showing more-prompt. if (*s >= ' ' && !cmdmsg_rl) { - if (has_mbyte) { - if (enc_utf8 && maxlen >= 0) - /* avoid including composing chars after the end */ - l = utfc_ptr2len_len(s, (int)((str + maxlen) - s)); - else - l = (*mb_ptr2len)(s); - s = screen_puts_mbyte((char_u *)s, l, attr); + if (maxlen >= 0) { + // Avoid including composing chars after the end. + l = utfc_ptr2len_len(s, (int)((str + maxlen) - s)); } else { - msg_screen_putchar(*s++, attr); + l = utfc_ptr2len(s); } + s = screen_puts_mbyte((char_u *)s, l, attr); did_last_char = true; } else { did_last_char = false; From dc523eed8ec2ea238dde21f39fdbb6343227c16e Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 20:59:44 +0300 Subject: [PATCH 31/53] =?UTF-8?q?fileio:=20Silence=20=E2=80=9C!=3D=20ident?= =?UTF-8?q?ical=20subexpressions=E2=80=9D=20warning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/nvim/os/fileio.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c index 3c47c66196..27eb448c3d 100644 --- a/src/nvim/os/fileio.c +++ b/src/nvim/os/fileio.c @@ -47,6 +47,7 @@ int file_open(FileDescriptor *const ret_fp, const char *const fname, int os_open_flags = 0; int fd; TriState wr = kNone; + // -V:FLAG:501 #define FLAG(flags, flag, fcntl_flags, wrval, cond) \ do { \ if (flags & flag) { \ From 84aa457ccdf88baeee1e87ba763fafe0ff77095e Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:02:43 +0300 Subject: [PATCH 32/53] =?UTF-8?q?os/env:=20Fix=20=E2=80=9Cinvalid=20pointe?= =?UTF-8?q?r=20to=20local=E2=80=9D=20false=20positive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/nvim/os/env.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index ad51e598c1..f3187de182 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -641,7 +641,7 @@ char *vim_getenv(const char *name) exe_name, "share" _PATHSEPSTR "nvim" _PATHSEPSTR "runtime" _PATHSEPSTR, MAXPATHL) == OK) { - vim_path = exe_name; + vim_path = exe_name; // -V507 } } } @@ -675,6 +675,7 @@ char *vim_getenv(const char *name) vim_path = NULL; } } + assert(vim_path != exe_name); } #ifdef HAVE_PATHDEF From cdbfff077b23d666036bd9967756938df9044b38 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:05:50 +0300 Subject: [PATCH 33/53] =?UTF-8?q?ops:=20Silence=20=E2=80=9Ccounter=20not?= =?UTF-8?q?=20used=20in=20loop=E2=80=9D=20false=20positive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/nvim/ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 5212ec45ab..6ea3a45049 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2785,7 +2785,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) } if (curbuf->terminal) { - for (int i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { // -V756 // feed the lines to the terminal for (size_t j = 0; j < y_size; j++) { if (j) { From 54bd78b8a8d212a0278b1d9517dd0dcc4df79a0b Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:06:22 +0300 Subject: [PATCH 34/53] normal: Remove unneeded assignment --- src/nvim/normal.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 388ddfc8bb..1809b98586 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -694,7 +694,6 @@ static void normal_get_additional_char(NormalState *s) if (langmap_active) { // Undo the decrement done above no_mapping++; - State = NORMAL_BUSY; } State = NORMAL_BUSY; s->need_flushbuf |= add_to_showcmd(*cp); From b5db7cde366ae159aee6826167b68c3aff0cdf19 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:08:12 +0300 Subject: [PATCH 35/53] normal: Clarify the code Current variant works only because of PUT_FIXINDENT being equal to true. --- src/nvim/normal.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 1809b98586..d7c7c7d48c 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -2336,7 +2336,8 @@ do_mouse ( if ((State & REPLACE_FLAG) && !yank_register_mline(regname)) insert_reg(regname, true); else { - do_put(regname, NULL, BACKWARD, 1L, fixindent | PUT_CURSEND); + do_put(regname, NULL, BACKWARD, 1L, + (fixindent ? PUT_FIXINDENT : 0) | PUT_CURSEND); /* Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r */ AppendCharToRedobuff(Ctrl_R); @@ -2688,7 +2689,8 @@ do_mouse ( */ if (restart_edit != 0) where_paste_started = curwin->w_cursor; - do_put(regname, NULL, dir, count, fixindent | PUT_CURSEND); + do_put(regname, NULL, dir, count, + (fixindent ? PUT_FIXINDENT : 0)| PUT_CURSEND); } /* * Ctrl-Mouse click or double click in a quickfix window jumps to the From aa3b1f695f699e189d5190c57e6c5e2bce4b0c9e Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:09:31 +0300 Subject: [PATCH 36/53] normal: Add figure braces so that code is clearer --- src/nvim/normal.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/nvim/normal.c b/src/nvim/normal.c index d7c7c7d48c..9340a45f62 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -7613,11 +7613,13 @@ static void nv_record(cmdarg_T *cap) if (cap->nchar == ':' || cap->nchar == '/' || cap->nchar == '?') { stuffcharReadbuff(cap->nchar); stuffcharReadbuff(K_CMDWIN); - } else - /* (stop) recording into a named register, unless executing a - * register */ - if (!Exec_reg && do_record(cap->nchar) == false) - clearopbeep(cap->oap); + } else { + // (stop) recording into a named register, unless executing a + // register. + if (!Exec_reg && do_record(cap->nchar) == false) { + clearopbeep(cap->oap); + } + } } } From be9d98cb45aab402b7666776ad1288b9a79bb0c1 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:10:40 +0300 Subject: [PATCH 37/53] quickfix: Remove unneeded condition fmt_ptr was checked for being NULL in if() condition earlier. --- src/nvim/quickfix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 4fa5c85abd..33b832c033 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -856,7 +856,7 @@ restofline: if (fmt_ptr == NULL) { qi->qf_multiline = qi->qf_multiignore = false; } - } else if (fmt_ptr != NULL) { + } else { // honor %> item if (fmt_ptr->conthere) { fmt_start = fmt_ptr; From 4e7150ee94d967ff51cbef24a7e18f71290ed9a2 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:11:37 +0300 Subject: [PATCH 38/53] quicfix: Remove duplicate condition --- src/nvim/quickfix.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 33b832c033..af055e9b75 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -3284,7 +3284,6 @@ void ex_cc(exarg_T *eap) || eap->cmdidx == CMD_lrewind || eap->cmdidx == CMD_lfirst || eap->cmdidx == CMD_llast - || eap->cmdidx == CMD_llast || eap->cmdidx == CMD_ldo || eap->cmdidx == CMD_lfdo) { qi = GET_LOC_LIST(curwin); @@ -3341,7 +3340,6 @@ void ex_cnext(exarg_T *eap) || eap->cmdidx == CMD_lnfile || eap->cmdidx == CMD_lNfile || eap->cmdidx == CMD_lpfile - || eap->cmdidx == CMD_lpfile || eap->cmdidx == CMD_ldo || eap->cmdidx == CMD_lfdo) { qi = GET_LOC_LIST(curwin); From b396a3f72edb3fb345e516a12b92991b249da572 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:13:49 +0300 Subject: [PATCH 39/53] quicfix: Avoid possible NULL dereference --- src/nvim/quickfix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index af055e9b75..1241841885 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -984,7 +984,7 @@ qf_init_ext( } // Use the local value of 'errorformat' if it's set. - if (errorformat == p_efm && tv == NULL && *buf->b_p_efm != NUL) { + if (errorformat == p_efm && tv == NULL && buf && *buf->b_p_efm != NUL) { efm = buf->b_p_efm; } else { efm = errorformat; From a65867542d291cda6cdd68e56e0d5d3866dbbb72 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:17:08 +0300 Subject: [PATCH 40/53] screen: Remove unneeded check --- src/nvim/screen.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/nvim/screen.c b/src/nvim/screen.c index febca105e9..79596f73cd 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -1016,9 +1016,7 @@ static void win_update(win_T *wp) linenr_T from, to; if (VIsual_active) { - if (VIsual_active - && (VIsual_mode != wp->w_old_visual_mode - || type == INVERTED_ALL)) { + if (VIsual_mode != wp->w_old_visual_mode || type == INVERTED_ALL) { /* * If the type of Visual selection changed, redraw the whole * selection. Also when the ownership of the X selection is From 7cf4b0ac06c7d6675a05924b6aff3850fde3bcf2 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:18:00 +0300 Subject: [PATCH 41/53] =?UTF-8?q?screen:=20Silence=20=E2=80=9Cbuffer=20und?= =?UTF-8?q?erflow=E2=80=9D=20warning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/nvim/screen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 79596f73cd..cf116e1930 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -2447,7 +2447,7 @@ win_line ( } else { /* Long line, use only the last SPWORDLEN bytes. */ nextlinecol = v - SPWORDLEN; - memmove(nextline, line + nextlinecol, SPWORDLEN); + memmove(nextline, line + nextlinecol, SPWORDLEN); // -V512 nextline_idx = SPWORDLEN + 1; } } From 48ad8e0ff1ba721a5607c20f48e813400041299c Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:22:02 +0300 Subject: [PATCH 42/53] screen: Silence NULL dereference false positive Based on the loop condition when shl_flag is true cur != NULL. --- src/nvim/screen.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/nvim/screen.c b/src/nvim/screen.c index cf116e1930..db757a54f5 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -2579,13 +2579,14 @@ win_line ( * Do this for both search_hl and the match list. */ cur = wp->w_match_head; - shl_flag = FALSE; - while (cur != NULL || shl_flag == FALSE) { - if (shl_flag == FALSE) { + shl_flag = false; + while (cur != NULL || !shl_flag) { + if (!shl_flag) { shl = &search_hl; - shl_flag = TRUE; - } else - shl = &cur->hl; + shl_flag = true; + } else { + shl = &cur->hl; // -V595 + } shl->startcol = MAXCOL; shl->endcol = MAXCOL; shl->attr_cur = 0; @@ -5536,13 +5537,14 @@ static void prepare_search_hl(win_T *wp, linenr_T lnum) * Do this both for search_hl and the match list. */ cur = wp->w_match_head; - shl_flag = FALSE; - while (cur != NULL || shl_flag == FALSE) { - if (shl_flag == FALSE) { + shl_flag = false; + while (cur != NULL || shl_flag == false) { + if (shl_flag == false) { shl = &search_hl; - shl_flag = TRUE; - } else - shl = &cur->hl; + shl_flag = true; + } else { + shl = &cur->hl; // -V595 + } if (shl->rm.regprog != NULL && shl->lnum == 0 && re_multiline(shl->rm.regprog)) { From e131194db71c5fc20148ea6e463de997917f6c0a Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:22:46 +0300 Subject: [PATCH 43/53] screen: Remove unneeded condition Already checked in outer if() --- src/nvim/screen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nvim/screen.c b/src/nvim/screen.c index db757a54f5..431f74508d 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -2784,8 +2784,8 @@ win_line ( // draw 'breakindent': indent wrapped text accodringly if (draw_state == WL_BRI - 1 && n_extra == 0) { draw_state = WL_BRI; - if (wp->w_p_bri && n_extra == 0 && row != startrow && filler_lines == 0) { - char_attr = 0; // was: hl_attr(HLF_AT); + if (wp->w_p_bri && row != startrow && filler_lines == 0) { + char_attr = 0; // was: hl_attr(HLF_AT); if (diff_hlf != (hlf_T)0) { char_attr = hl_attr(diff_hlf); From c0cbc507202231d5dd9c5c8669e6116f3344d535 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:26:07 +0300 Subject: [PATCH 44/53] screen: Remove another portion of has_mbyte/friends-checking stuff --- src/nvim/screen.c | 95 +++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 52 deletions(-) diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 431f74508d..66b52c3b25 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -5330,43 +5330,39 @@ void screen_puts_len(char_u *text, int textlen, int row, int col, int attr) c = *ptr; /* check if this is the first byte of a multibyte */ if (l_has_mbyte) { - if (l_enc_utf8 && len > 0) + if (len > 0) { mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); - else - mbyte_blen = (*mb_ptr2len)(ptr); - if (l_enc_dbcs == DBCS_JPNU && c == 0x8e) - mbyte_cells = 1; - else if (l_enc_dbcs != 0) - mbyte_cells = mbyte_blen; - else { /* enc_utf8 */ - if (len >= 0) - u8c = utfc_ptr2char_len(ptr, u8cc, - (int)((text + len) - ptr)); - else - u8c = utfc_ptr2char(ptr, u8cc); - mbyte_cells = utf_char2cells(u8c); - if (p_arshape && !p_tbidi && arabic_char(u8c)) { - /* Do Arabic shaping. */ - if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) { - /* Past end of string to be displayed. */ - nc = NUL; - nc1 = NUL; - } else { - nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, - (int)((text + len) - ptr - mbyte_blen)); - nc1 = pcc[0]; - } - pc = prev_c; - prev_c = u8c; - u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); - } else - prev_c = u8c; - if (col + mbyte_cells > screen_Columns) { - /* Only 1 cell left, but character requires 2 cells: - * display a '>' in the last column to avoid wrapping. */ - c = '>'; - mbyte_cells = 1; + } else { + mbyte_blen = utfc_ptr2len(ptr); + } + if (len >= 0) { + u8c = utfc_ptr2char_len(ptr, u8cc, (int)((text + len) - ptr)); + } else { + u8c = utfc_ptr2char(ptr, u8cc); + } + mbyte_cells = utf_char2cells(u8c); + if (p_arshape && !p_tbidi && arabic_char(u8c)) { + // Do Arabic shaping. + if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) { + // Past end of string to be displayed. + nc = NUL; + nc1 = NUL; + } else { + nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, + (int)((text + len) - ptr - mbyte_blen)); + nc1 = pcc[0]; } + pc = prev_c; + prev_c = u8c; + u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); + } else { + prev_c = u8c; + } + if (col + mbyte_cells > screen_Columns) { + // Only 1 cell left, but character requires 2 cells: + // display a '>' in the last column to avoid wrapping. */ + c = '>'; + mbyte_cells = 1; } } @@ -5374,16 +5370,11 @@ void screen_puts_len(char_u *text, int textlen, int row, int col, int attr) force_redraw_next = FALSE; need_redraw = ScreenLines[off] != c - || (mbyte_cells == 2 - && ScreenLines[off + 1] != (l_enc_dbcs ? ptr[1] : 0)) - || (l_enc_dbcs == DBCS_JPNU - && c == 0x8e - && ScreenLines2[off] != ptr[1]) - || (l_enc_utf8 - && (ScreenLinesUC[off] != - (u8char_T)(c < 0x80 && u8cc[0] == 0 ? 0 : u8c) - || (ScreenLinesUC[off] != 0 - && screen_comp_differs(off, u8cc)))) + || (mbyte_cells == 2 && ScreenLines[off + 1] != 0) + || (ScreenLinesUC[off] != + (u8char_T)(c < 0x80 && u8cc[0] == 0 ? 0 : u8c) + || (ScreenLinesUC[off] != 0 + && screen_comp_differs(off, u8cc))) || ScreenAttrs[off] != attr || exmode_active; @@ -6103,8 +6094,7 @@ retry: if (new_ScreenLinesC[i] == NULL) break; if (new_ScreenLines == NULL - || (l_enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) - || (l_enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) + || (new_ScreenLinesUC == NULL || i != p_mco) || new_ScreenAttrs == NULL || new_LineOffset == NULL || new_LineWraps == NULL @@ -6189,13 +6179,14 @@ retry: ScreenLinesC[i] + LineOffset[old_row], (size_t)len * sizeof(u8char_T)); } - if (l_enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) + if (ScreenLines2 != NULL) { memmove(new_ScreenLines2 + new_LineOffset[new_row], - ScreenLines2 + LineOffset[old_row], - (size_t)len * sizeof(schar_T)); + ScreenLines2 + LineOffset[old_row], + (size_t)len * sizeof(schar_T)); + } memmove(new_ScreenAttrs + new_LineOffset[new_row], - ScreenAttrs + LineOffset[old_row], - (size_t)len * sizeof(sattr_T)); + ScreenAttrs + LineOffset[old_row], + (size_t)len * sizeof(sattr_T)); } } } From 316789e14c3910c0b4c5dd710a1c82ebd7b01ac2 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:33:10 +0300 Subject: [PATCH 45/53] =?UTF-8?q?tag:=20Silence=20=E2=80=9Cbuffer=20underf?= =?UTF-8?q?low=E2=80=9D=20warning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/nvim/tag.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nvim/tag.c b/src/nvim/tag.c index f01b8b8ab1..1ce2a4e2eb 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -1222,9 +1222,9 @@ find_tags ( if (has_re && orgpat.regmatch.regprog == NULL) goto findtag_end; - /* This is only to avoid a compiler warning for using search_info - * uninitialised. */ - memset(&search_info, 0, (size_t)1); + // This is only to avoid a compiler warning for using search_info + // uninitialised. + memset(&search_info, 0, 1); // -V512 /* * When finding a specified number of matches, first try with matching From 76783963ebc90ca565311489bb2206b208d2e147 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:34:15 +0300 Subject: [PATCH 46/53] =?UTF-8?q?tag:=20Fix=20=E2=80=9Cinitialized=20twice?= =?UTF-8?q?=20successively=E2=80=9D=20false=20positive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/nvim/tag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 1ce2a4e2eb..0c7244cbb3 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -2534,7 +2534,7 @@ jumpto_tag ( } } p_ws = save_p_ws; - p_ic = save_p_ic; + p_ic = save_p_ic; // -V519 p_scs = save_p_scs; /* A search command may have positioned the cursor beyond the end From 69ebfb8d8ea26061a4fbfe9ee07d7bfff49e6a2b Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:35:50 +0300 Subject: [PATCH 47/53] regexp: Fix warning about octal constant --- src/nvim/regexp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 4b5e17b00b..e15a2eebe5 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -2398,7 +2398,7 @@ collection: regc('\b'); break; case CLASS_ESCAPE: - regc('\033'); + regc(ESC); break; } } else { From b7118a008af1f0a15f7cfbe070a1f590310cc7b5 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:36:53 +0300 Subject: [PATCH 48/53] =?UTF-8?q?regexp:=20Remove=20another=20has=5Fmbyte/?= =?UTF-8?q?=E2=80=A6-checking=20stuff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/nvim/regexp.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index e15a2eebe5..284cb27c40 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -2923,13 +2923,8 @@ static void skipchr(void) else prevchr_len = 0; if (regparse[prevchr_len] != NUL) { - if (enc_utf8) - /* exclude composing chars that mb_ptr2len does include */ - prevchr_len += utf_ptr2len(regparse + prevchr_len); - else if (has_mbyte) - prevchr_len += (*mb_ptr2len)(regparse + prevchr_len); - else - ++prevchr_len; + // Exclude composing chars that utfc_ptr2len does include. + prevchr_len += utf_ptr2len(regparse + prevchr_len); } regparse += prevchr_len; prev_at_start = at_start; From 30561afe4128ab0c5371af00641d5c5a682d6270 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:38:06 +0300 Subject: [PATCH 49/53] regexp: Silence octal constant warning --- src/nvim/regexp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 284cb27c40..7be89c2d7e 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -3047,7 +3047,7 @@ static int getoctchrs(void) int c; int i; - for (i = 0; i < 3 && nr < 040; ++i) { + for (i = 0; i < 3 && nr < 040; i++) { // -V536 c = regparse[0]; if (c < '0' || c > '7') break; From 372b6af8ea09bced16e8c793cbab304d2393bfa6 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:41:55 +0300 Subject: [PATCH 50/53] =?UTF-8?q?regexp=5Fnfa:=20Remove=20another=20has=5F?= =?UTF-8?q?mbyte/=E2=80=A6-checking=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/nvim/regexp_nfa.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index caf26fdd35..67a405daf5 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -2772,15 +2772,10 @@ static int nfa_max_width(nfa_state_T *startstate, int depth) case NFA_ANY: case NFA_START_COLL: case NFA_START_NEG_COLL: - /* matches some character, including composing chars */ - if (enc_utf8) - len += MB_MAXBYTES; - else if (has_mbyte) - len += 2; - else - ++len; + // Matches some character, including composing chars. + len += MB_MAXBYTES; if (state->c != NFA_ANY) { - /* skip over the characters */ + // Skip over the characters. state = state->out1->out; continue; } From 9d302c60f084c33c05b758cae12cc2dfa775e48e Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 21:42:20 +0300 Subject: [PATCH 51/53] regexp_nfa: Remove octal constant --- src/nvim/regexp_nfa.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 67a405daf5..506e6277e9 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -4407,8 +4407,9 @@ static int check_char_class(int class, int c) return OK; break; case NFA_CLASS_ESCAPE: - if (c == '\033') + if (c == ESC) { return OK; + } break; default: From 58300d70d26969546e204983f8b4e505771ec8dd Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 22:20:19 +0300 Subject: [PATCH 52/53] *: Fix linter errors --- src/nvim/eval.c | 9 +++++---- src/nvim/ex_docmd.c | 3 +-- src/nvim/normal.c | 6 +++--- src/nvim/screen.c | 10 ++++------ 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index cf55b42bdf..7c5b23f567 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2742,11 +2742,12 @@ void ex_call(exarg_T *eap) * call, and the loop is broken. */ if (eap->skip) { - ++emsg_skip; - lnum = eap->line2; /* do it once, also with an invalid range */ - } else + emsg_skip++; + lnum = eap->line2; // Do it once, also with an invalid range. + } else { lnum = eap->line1; - for (; lnum <= eap->line2; ++lnum) { + } + for (; lnum <= eap->line2; lnum++) { if (!eap->skip && eap->addr_count > 0) { // -V560 curwin->w_cursor.lnum = lnum; curwin->w_cursor.col = 0; diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 0e399c9fb3..17b3b512ef 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -4095,8 +4095,7 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp) xpc.xp_context = EXPAND_FILES; if (p_wic) options += WILD_ICASE; - p = ExpandOne(&xpc, eap->arg, NULL, - options, WILD_EXPAND_FREE); + p = ExpandOne(&xpc, eap->arg, NULL, options, WILD_EXPAND_FREE); if (p == NULL) { return FAIL; } diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 9340a45f62..7f087dcd20 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -2333,9 +2333,9 @@ do_mouse ( if (regname == 0 && eval_has_provider("clipboard")) { regname = '*'; } - if ((State & REPLACE_FLAG) && !yank_register_mline(regname)) + if ((State & REPLACE_FLAG) && !yank_register_mline(regname)) { insert_reg(regname, true); - else { + } else { do_put(regname, NULL, BACKWARD, 1L, (fixindent ? PUT_FIXINDENT : 0) | PUT_CURSEND); @@ -7616,7 +7616,7 @@ static void nv_record(cmdarg_T *cap) } else { // (stop) recording into a named register, unless executing a // register. - if (!Exec_reg && do_record(cap->nchar) == false) { + if (!Exec_reg && do_record(cap->nchar) == FAIL) { clearopbeep(cap->oap); } } diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 66b52c3b25..a8993be4e5 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -1017,11 +1017,9 @@ static void win_update(win_T *wp) if (VIsual_active) { if (VIsual_mode != wp->w_old_visual_mode || type == INVERTED_ALL) { - /* - * If the type of Visual selection changed, redraw the whole - * selection. Also when the ownership of the X selection is - * gained or lost. - */ + // If the type of Visual selection changed, redraw the whole + // selection. Also when the ownership of the X selection is + // gained or lost. if (curwin->w_cursor.lnum < VIsual.lnum) { from = curwin->w_cursor.lnum; to = VIsual.lnum; @@ -5349,7 +5347,7 @@ void screen_puts_len(char_u *text, int textlen, int row, int col, int attr) nc1 = NUL; } else { nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, - (int)((text + len) - ptr - mbyte_blen)); + (int)((text + len) - ptr - mbyte_blen)); nc1 = pcc[0]; } pc = prev_c; From 2eb9150a4fcb8f43599e5f470cbcb3a12195d910 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Apr 2017 23:58:32 +0300 Subject: [PATCH 53/53] buffer: Adjust where do_buffer call is located It is located there in Vim, but in dd7657c1605246e8f7ade35184069a09dc254e84 position was for some reason swapped. --- src/nvim/buffer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 292eb03a16..e48b7846ae 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -741,12 +741,13 @@ static void clear_wininfo(buf_T *buf) */ void goto_buffer(exarg_T *eap, int start, int dir, int count) { - (void)do_buffer(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO, - start, dir, count, eap->forceit); bufref_T old_curbuf; set_bufref(&old_curbuf, curbuf); swap_exists_action = SEA_DIALOG; + (void)do_buffer(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO, + start, dir, count, eap->forceit); + if (swap_exists_action == SEA_QUIT && *eap->cmd == 's') { cleanup_T cs;