aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/eval.c2
-rw-r--r--src/nvim/ex_docmd.c17
-rw-r--r--src/nvim/menu.c20
-rw-r--r--src/nvim/normal.c8
-rw-r--r--src/nvim/path.c2
-rw-r--r--src/nvim/quickfix.c6
-rw-r--r--src/nvim/tag.c2
-rw-r--r--src/nvim/testdir/test_diffmode.vim52
8 files changed, 83 insertions, 26 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 04a9abe41a..1c981d65e0 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -1619,7 +1619,7 @@ void list_hashtable_vars(hashtab_T *ht, const char *prefix, int empty,
char buf[IOSIZE];
// apply :filter /pat/ to variable name
- xstrlcpy(buf, prefix, IOSIZE - 1);
+ xstrlcpy(buf, prefix, IOSIZE);
xstrlcat(buf, (char *)di->di_key, IOSIZE);
if (message_filtered((char_u *)buf)) {
continue;
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index c557bb2438..c93f9fe6f2 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -1772,7 +1772,7 @@ static char_u * do_one_cmd(char_u **cmdlinep,
// count, it's a buffer name.
///
if ((ea.argt & EX_COUNT) && ascii_isdigit(*ea.arg)
- && (!(ea.argt & EX_BUFNAME) || *(p = skipdigits(ea.arg)) == NUL
+ && (!(ea.argt & EX_BUFNAME) || *(p = skipdigits(ea.arg + 1)) == NUL
|| ascii_iswhite(*p))) {
n = getdigits_long(&ea.arg, false, -1);
ea.arg = skipwhite(ea.arg);
@@ -2790,15 +2790,18 @@ static struct cmdmod {
*/
int modifier_len(char_u *cmd)
{
- int i, j;
char_u *p = cmd;
- if (ascii_isdigit(*cmd))
- p = skipwhite(skipdigits(cmd));
- for (i = 0; i < (int)ARRAY_SIZE(cmdmods); ++i) {
- for (j = 0; p[j] != NUL; ++j)
- if (p[j] != cmdmods[i].name[j])
+ if (ascii_isdigit(*cmd)) {
+ p = skipwhite(skipdigits(cmd + 1));
+ }
+ for (int i = 0; i < (int)ARRAY_SIZE(cmdmods); i++) {
+ int j;
+ for (j = 0; p[j] != NUL; j++) {
+ if (p[j] != cmdmods[i].name[j]) {
break;
+ }
+ }
if (j >= cmdmods[i].minlen
&& !ASCII_ISALPHA(p[j])
&& (p == cmd || cmdmods[i].has_count)) {
diff --git a/src/nvim/menu.c b/src/nvim/menu.c
index ac3b7768e6..112f51fc64 100644
--- a/src/nvim/menu.c
+++ b/src/nvim/menu.c
@@ -1069,7 +1069,7 @@ char_u *get_menu_names(expand_T *xp, int idx)
#define TBUFFER_LEN 256
static char_u tbuffer[TBUFFER_LEN]; /*hack*/
char_u *str;
- static int should_advance = FALSE;
+ static bool should_advance = false;
if (idx == 0) { /* first call: start at first item */
menu = expand_menu;
@@ -1089,12 +1089,13 @@ char_u *get_menu_names(expand_T *xp, int idx)
if (menu->modes & expand_modes) {
if (menu->children != NULL) {
- if (should_advance)
- STRLCPY(tbuffer, menu->en_dname, TBUFFER_LEN - 1);
- else {
- STRLCPY(tbuffer, menu->dname, TBUFFER_LEN - 1);
- if (menu->en_dname == NULL)
- should_advance = TRUE;
+ if (should_advance) {
+ STRLCPY(tbuffer, menu->en_dname, TBUFFER_LEN);
+ } else {
+ STRLCPY(tbuffer, menu->dname, TBUFFER_LEN);
+ if (menu->en_dname == NULL) {
+ should_advance = true;
+ }
}
/* hack on menu separators: use a 'magic' char for the separator
* so that '.' in names gets escaped properly */
@@ -1105,8 +1106,9 @@ char_u *get_menu_names(expand_T *xp, int idx)
str = menu->en_dname;
else {
str = menu->dname;
- if (menu->en_dname == NULL)
- should_advance = TRUE;
+ if (menu->en_dname == NULL) {
+ should_advance = true;
+ }
}
}
} else
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 2f4c441beb..13706fb14a 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -1942,10 +1942,12 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
case OP_FORMAT:
if (*curbuf->b_p_fex != NUL) {
op_formatexpr(oap); // use expression
- } else if (*p_fp != NUL || *curbuf->b_p_fp != NUL) {
- op_colon(oap); // use external command
} else {
- op_format(oap, false); // use internal function
+ if (*p_fp != NUL || *curbuf->b_p_fp != NUL) {
+ op_colon(oap); // use external command
+ } else {
+ op_format(oap, false); // use internal function
+ }
}
break;
diff --git a/src/nvim/path.c b/src/nvim/path.c
index 3e1713fbdd..fe50be5ea1 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -65,7 +65,7 @@ FileComparison path_full_compare(char_u *const s1, char_u *const s2,
if (expandenv) {
expand_env(s1, exp1, MAXPATHL);
} else {
- xstrlcpy((char *)exp1, (const char *)s1, MAXPATHL - 1);
+ xstrlcpy((char *)exp1, (const char *)s1, MAXPATHL);
}
bool id_ok_1 = os_fileid((char *)exp1, &file_id_1);
bool id_ok_2 = os_fileid((char *)s2, &file_id_2);
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index 464d72eccb..e318e9a078 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -3919,13 +3919,13 @@ static int qf_buf_add_line(buf_T *buf, linenr_T lnum, const qfline_T *qfp,
buf_T *errbuf;
if (qfp->qf_module != NULL) {
- STRLCPY(IObuff, qfp->qf_module, IOSIZE - 1);
+ STRLCPY(IObuff, qfp->qf_module, IOSIZE);
len = (int)STRLEN(IObuff);
} else if (qfp->qf_fnum != 0
&& (errbuf = buflist_findnr(qfp->qf_fnum)) != NULL
&& errbuf->b_fname != NULL) {
if (qfp->qf_type == 1) { // :helpgrep
- STRLCPY(IObuff, path_tail(errbuf->b_fname), IOSIZE - 1);
+ STRLCPY(IObuff, path_tail(errbuf->b_fname), IOSIZE);
} else {
// Shorten the file name if not done already.
// For optimization, do this only for the first entry in a
@@ -3938,7 +3938,7 @@ static int qf_buf_add_line(buf_T *buf, linenr_T lnum, const qfline_T *qfp,
}
shorten_buf_fname(errbuf, dirname, false);
}
- STRLCPY(IObuff, errbuf->b_fname, IOSIZE - 1);
+ STRLCPY(IObuff, errbuf->b_fname, IOSIZE);
}
len = (int)STRLEN(IObuff);
} else {
diff --git a/src/nvim/tag.c b/src/nvim/tag.c
index f0e48013b2..ab35c936ca 100644
--- a/src/nvim/tag.c
+++ b/src/nvim/tag.c
@@ -3010,7 +3010,7 @@ static int find_extra(char_u **pp)
// Repeat for addresses separated with ';'
for (;; ) {
if (ascii_isdigit(*str)) {
- str = skipdigits(str);
+ str = skipdigits(str + 1);
} else if (*str == '/' || *str == '?') {
str = skip_regexp(str + 1, *str, false, NULL);
if (*str != first_char) {
diff --git a/src/nvim/testdir/test_diffmode.vim b/src/nvim/testdir/test_diffmode.vim
index 21c1f98283..1ade11a8ed 100644
--- a/src/nvim/testdir/test_diffmode.vim
+++ b/src/nvim/testdir/test_diffmode.vim
@@ -781,17 +781,66 @@ func Test_diff_lastline()
bwipe!
endfunc
+func WriteDiffFiles(buf, list1, list2)
+ call writefile(a:list1, 'Xfile1')
+ call writefile(a:list2, 'Xfile2')
+ if a:buf
+ call term_sendkeys(a:buf, ":checktime\<CR>")
+ endif
+endfunc
+" Verify a screendump with both the internal and external diff.
+func VerifyBoth(buf, dumpfile, extra)
+ " trailing : for leaving the cursor on the command line
+ for cmd in [":set diffopt=filler" . a:extra . "\<CR>:", ":set diffopt+=internal\<CR>:"]
+ call term_sendkeys(a:buf, cmd)
+ if VerifyScreenDump(a:buf, a:dumpfile, {}, cmd =~ 'internal' ? 'internal' : 'external')
+ break " don't let the next iteration overwrite the "failed" file.
+ " don't let the next iteration overwrite the "failed" file.
+ return
+ endif
+ endfor
+
+ " also test unified diff
+ call term_sendkeys(a:buf, ":call SetupUnified()\<CR>:")
+ call VerifyScreenDump(a:buf, a:dumpfile, {}, 'unified')
+ call term_sendkeys(a:buf, ":call StopUnified()\<CR>:")
+endfunc
+
+" Verify a screendump with the internal diff only.
+func VerifyInternal(buf, dumpfile, extra)
+ call term_sendkeys(a:buf, ":diffupdate!\<CR>")
+ " trailing : for leaving the cursor on the command line
+ call term_sendkeys(a:buf, ":set diffopt=internal,filler" . a:extra . "\<CR>:")
+ call TermWait(a:buf)
+ call VerifyScreenDump(a:buf, a:dumpfile, {})
+endfunc
+
func Test_diff_screen()
CheckScreendump
CheckFeature menu
+ let lines =<< trim END
+ func UnifiedDiffExpr()
+ " Prepend some text to check diff type detection
+ call writefile(['warning', ' message'], v:fname_out)
+ silent exe '!diff -u ' .. v:fname_in .. ' ' .. v:fname_new .. '>>' .. v:fname_out
+ endfunc
+ func SetupUnified()
+ set diffexpr=UnifiedDiffExpr()
+ endfunc
+ func StopUnified()
+ set diffexpr=
+ endfunc
+ END
+ call writefile(lines, 'XdiffSetup')
+
" clean up already existing swap files, just in case
call delete('.Xfile1.swp')
call delete('.Xfile2.swp')
" Test 1: Add a line in beginning of file 2
call WriteDiffFiles(0, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
- let buf = RunVimInTerminal('-d Xfile1 Xfile2', {})
+ let buf = RunVimInTerminal('-d -S XdiffSetup Xfile1 Xfile2', {})
" Set autoread mode, so that Vim won't complain once we re-write the test
" files
call term_sendkeys(buf, ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w")
@@ -911,6 +960,7 @@ func Test_diff_screen()
call StopVimInTerminal(buf)
call delete('Xfile1')
call delete('Xfile2')
+ call delete('XdiffSetup')
endfunc
func Test_diff_with_cursorline()