patch 9.2.0595: MS-Windows: Wrong buffer size calculation for gvimext

Commit: 
https://github.com/vim/vim/commit/ed49b48482297ab1ca126032321b34d19bbe8cb3
Author: K.Takata <[email protected]>
Date:   Thu Jun 4 19:40:30 2026 +0000

    patch 9.2.0595: MS-Windows: Wrong buffer size calculation for gvimext
    
    Problem:  MS-Windows: Wrong buffer size calculation for gvimext
              (after 7e6d3bd3da555e151ba518081a964a0cdb39ac33).
    Solution: Declare buffer as WCHAR, drop type casts, use
              ARRAY_LENGTH macro (Ken Takata).
    
    closes: #20424
    
    Signed-off-by: K.Takata <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/GvimExt/gvimext.cpp b/src/GvimExt/gvimext.cpp
index f98423c15..6d07b8b3c 100644
--- a/src/GvimExt/gvimext.cpp
+++ b/src/GvimExt/gvimext.cpp
@@ -16,6 +16,8 @@
 
 #include "gvimext.h"
 
+#define ARRAY_LENGTH(a) (sizeof(a) / sizeof((a)[0]))
+
 static char *searchpath(char *name);
 
 // Always get an error while putting the following stuff to the
@@ -849,7 +851,7 @@ STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO 
lpcmi)
                    // If execution reaches this point we likely have an
                    // inconsistency between the code that setup the menus
                    // and this code that determines what the user
-                   // selected.  This should be detected and fixed during 
+                   // selected.  This should be detected and fixed during
                    // development.
                    return E_FAIL;
            }
@@ -957,16 +959,14 @@ BOOL CShellExt::LoadMenuIcon()
 searchpath(char *name)
 {
     static char widename[2 * BUFSIZE];
-    static char location[2 * BUFSIZE + 2];
+    WCHAR location[BUFSIZE + 1];
 
     // There appears to be a bug in FindExecutableA() on Windows NT.
     // Use FindExecutableW() instead...
-    MultiByteToWideChar(CP_ACP, 0, (LPCSTR)name, -1,
-           (LPWSTR)widename, BUFSIZE);
-    if (FindExecutableW((LPCWSTR)widename, (LPCWSTR)"",
-               (LPWSTR)location) > (HINSTANCE)32)
+    MultiByteToWideChar(CP_ACP, 0, name, -1, (LPWSTR)widename, BUFSIZE);
+    if (FindExecutableW((LPCWSTR)widename, L"", location) > (HINSTANCE)32)
     {
-       WideCharToMultiByte(CP_ACP, 0, (LPWSTR)location, -1,
+       WideCharToMultiByte(CP_ACP, 0, location, -1,
                (LPSTR)widename, 2 * BUFSIZE, NULL, NULL);
        return widename;
     }
@@ -1002,7 +1002,7 @@ STDMETHODIMP CShellExt::InvokeSingleGvim(HWND hParent,
        DragQueryFileW((HDROP)medium.hGlobal,
                i,
                m_szFileUserClickedOn,
-               sizeof(m_szFileUserClickedOn));
+               ARRAY_LENGTH(m_szFileUserClickedOn));
 
        len = wcslen(cmdStrW) + wcslen(m_szFileUserClickedOn) + 4;
        if (len > cmdlen)
diff --git a/src/version.c b/src/version.c
index 65550ac00..80200eb4c 100644
--- a/src/version.c
+++ b/src/version.c
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    595,
 /**/
     594,
 /**/

-- 
-- 
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].
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1wVEEX-005cV0-0r%40256bit.org.

Raspunde prin e-mail lui