patch 9.0.1434: crash when adding package already in 'runtimepath'
Problem: Crash when adding package already in 'runtimepath'.
Solution: Change order for using 'runtimepath' entries. (closes #12215)
diff --git a/src/scriptfile.c b/src/scriptfile.c
index dd4a352..0afe201 100644
--- a/src/scriptfile.c
+++ b/src/scriptfile.c
@@ -718,18 +718,6 @@
char_u *cur_entry = entry;
copy_option_part(&entry, buf, MAXPATHL, ",");
- if (insp == NULL)
- {
- add_pathsep(buf);
- rtp_ffname = fix_fname(buf);
- if (rtp_ffname == NULL)
- goto theend;
- match = vim_fnamencmp(rtp_ffname, ffname, fname_len) == 0;
- vim_free(rtp_ffname);
- if (match)
- // Insert "ffname" after this entry (and comma).
- insp = entry;
- }
if ((p = (char_u *)strstr((char *)buf, "after")) != NULL
&& p > buf
@@ -743,6 +731,19 @@
after_insp = cur_entry;
break;
}
+
+ if (insp == NULL)
+ {
+ add_pathsep(buf);
+ rtp_ffname = fix_fname(buf);
+ if (rtp_ffname == NULL)
+ goto theend;
+ match = vim_fnamencmp(rtp_ffname, ffname, fname_len) == 0;
+ vim_free(rtp_ffname);
+ if (match)
+ // Insert "ffname" after this entry (and comma).
+ insp = entry;
+ }
}
if (insp == NULL)
diff --git a/src/testdir/test_packadd.vim b/src/testdir/test_packadd.vim
index 89b7817..b44494a 100644
--- a/src/testdir/test_packadd.vim
+++ b/src/testdir/test_packadd.vim
@@ -21,6 +21,13 @@
call mkdir(s:plugdir . '/plugin/also', 'p')
call mkdir(s:plugdir . '/ftdetect', 'p')
call mkdir(s:plugdir . '/after', 'p')
+
+ " This used to crash Vim
+ let &rtp = 'nosuchdir,' . s:plugdir . '/after'
+ packadd mytest
+ " plugdir should be inserted before plugdir/after
+ call assert_match('^nosuchdir,' . s:plugdir . ',', &rtp)
+
set rtp&
let rtp = &rtp
filetype on
diff --git a/src/version.c b/src/version.c
index 76f5f09..f87bc34 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1434,
+/**/
1433,
/**/
1432,