
# HG changeset patch
# User JiriS
# Date 1347374871 -7200
# Node ID 0df69a82a80c05663687b7ea37a2feec47baa441
# Parent  1052677493beb941eab0d1e33d63c73ee4148350
calling of mch_dirname, mch_chdir from vimLoadLib caused stack overflow

diff -r 1052677493be -r 0df69a82a80c src/os_win32.c
--- a/src/os_win32.c	Wed Sep 05 19:17:42 2012 +0200
+++ b/src/os_win32.c	Tue Sep 11 16:47:51 2012 +0200
@@ -288,18 +288,24 @@
 vimLoadLib(char *name)
 {
     HINSTANCE dll = NULL;
-    char old_dir[MAXPATHL];
+    TCHAR old_dir[MAXPATHL];
 
     if (exe_path == NULL)
 	get_exe_name();
-    if (exe_path != NULL && mch_dirname(old_dir, MAXPATHL) == OK)
+    if (exe_path != NULL && GetCurrentDirectory(MAXPATHL, old_dir) != 0)
     {
 	/* Change directory to where the executable is, both to make sure we
 	 * find a .dll there and to avoid looking for a .dll in the current
 	 * directory. */
-	mch_chdir(exe_path);
+	SetCurrentDirectory(exe_path);
 	dll = LoadLibrary(name);
-	mch_chdir(old_dir);
+	SetCurrentDirectory(old_dir);
+    }
+    else
+    {
+	/* We are not able to set directory where executable is or go back to
+	 * current directory. But we can try to load library anyway */
+	dll = LoadLibrary(name);
     }
     return dll;
 }

