diff src/main.c @ 11032:516391d8865f v8.0.0405

patch 8.0.0405: v:progpath may become invalid after :cd commit https://github.com/vim/vim/commit/08cab9608781c975b4acbad875862b842b29258d Author: Bram Moolenaar <Bram@vim.org> Date: Sat Mar 4 14:37:18 2017 +0100 patch 8.0.0405: v:progpath may become invalid after :cd Problem: v:progpath may become invalid after ":cd". Solution: Turn v:progpath into a full path if needed.
author Christian Brabandt <cb@256bit.org>
date Sat, 04 Mar 2017 14:45:05 +0100
parents 835604f3c37a
children fde2cdef6b97
line wrap: on
line diff
--- a/src/main.c
+++ b/src/main.c
@@ -57,6 +57,9 @@ static void main_start_gui(void);
 # if defined(HAS_SWAP_EXISTS_ACTION)
 static void check_swap_exists_action(void);
 # endif
+# ifdef FEAT_EVAL
+static void set_progpath(char_u *argv0);
+# endif
 # if defined(FEAT_CLIENTSERVER) || defined(PROTO)
 static void exec_on_server(mparm_T *parmp);
 static void prepare_server(mparm_T *parmp);
@@ -1694,7 +1697,7 @@ parse_command_name(mparm_T *parmp)
 
 #ifdef FEAT_EVAL
     set_vim_var_string(VV_PROGNAME, initstr, -1);
-    set_vim_var_string(VV_PROGPATH, (char_u *)parmp->argv[0], -1);
+    set_progpath((char_u *)parmp->argv[0]);
 #endif
 
     if (TOLOWER_ASC(initstr[0]) == 'r')
@@ -3417,7 +3420,7 @@ check_swap_exists_action(void)
 }
 #endif
 
-#endif
+#endif /* NO_VIM_MAIN */
 
 #if defined(STARTUPTIME) || defined(PROTO)
 static void time_diff(struct timeval *then, struct timeval *now);
@@ -3525,6 +3528,30 @@ time_msg(
 
 #endif
 
+#ifndef NO_VIM_MAIN
+    static void
+set_progpath(char_u *argv0)
+{
+    char_u *val = argv0;
+    char_u buf[MAXPATHL];
+
+    /* A relative path containing a "/" will become invalid when using ":cd",
+     * turn it into a full path.
+     * On MS-Windows "vim.exe" is found in the current directory, thus also do
+     * it when there is no path and the file exists. */
+    if ( !mch_isFullName(argv0)
+# ifdef WIN32
+	    && mch_can_exe(argv0, NULL, TRUE)
+# else
+	    && gettail(argv0) != argv0
+# endif
+	    && vim_FullName(argv0, buf, MAXPATHL, TRUE) != FAIL)
+	val = buf;
+    set_vim_var_string(VV_PROGPATH, val, -1);
+}
+
+#endif /* NO_VIM_MAIN */
+
 #if (defined(FEAT_CLIENTSERVER) && !defined(NO_VIM_MAIN)) || defined(PROTO)
 
 /*