Hi,

When 'enc' is utf-8, executable() may fail on very long filename which is
longer than _MAX_PATH bytes in UTF-8 and shorter than _MAX_PATH character in
UTF-16.
Here is an example on Japanese Windows:

C:\tmp>gvim -N -u NONE --cmd "set enc=utf-8" 
ああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああ.bat
:w
:echo glob('あ*.bat')
ああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああ.bat
:echo strlen(glob('あ*.bat'))
604   " longer than 260
:echo strchars(glob('あ*.bat'))
204   " shorter than 260
:echo executable(glob('あ*.bat'))
0     " 1 is expected.


Attached patch fixes the problem.

Regards,
Ken Takata

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
# HG changeset patch
# Parent 6ee3a815113c128147fa9831c2004916a7daba86
# Parent  1cc062c18ba99d25154a19f5e79ef75e74569935

diff --git a/src/os_win32.c b/src/os_win32.c
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -3364,11 +3364,18 @@ mch_writable(char_u *name)
     int
 mch_can_exe(char_u *name, char_u **path, int use_path)
 {
+#ifdef FEAT_MBYTE
+    /* WinNT and later can use _MAX_PATH wide characters for a pathname, which
+     * means that the maximum pathname is _MAX_PATH * 3 bytes when 'enc' is
+     * UTF-8. */
+    char_u	buf[_MAX_PATH * 3];
+#else
     char_u	buf[_MAX_PATH];
+#endif
     int		len = (int)STRLEN(name);
     char_u	*p;
 
-    if (len >= _MAX_PATH)	/* safety check */
+    if (len >= sizeof(buf))	/* safety check */
 	return FALSE;
     if (!use_path)
     {
@@ -3386,7 +3393,7 @@ mch_can_exe(char_u *name, char_u **path,
     /*
      * Loop over all extensions in $PATHEXT.
      */
-    vim_strncpy(buf, name, _MAX_PATH - 1);
+    vim_strncpy(buf, name, sizeof(buf) - 1);
     p = mch_getenv("PATHEXT");
     if (p == NULL)
 	p = (char_u *)".com;.exe;.bat;.cmd";
@@ -3401,7 +3408,7 @@ mch_can_exe(char_u *name, char_u **path,
 		++p;
 	}
 	else
-	    copy_option_part(&p, buf + len, _MAX_PATH - len, ";");
+	    copy_option_part(&p, buf + len, sizeof(buf) - len, ";");
 	if (executable_exists((char *)buf, path))
 	    return TRUE;
     }

Raspunde prin e-mail lui