Akihiro Sagawa : kernel32: Fix incorrect lastpart in GetFullPathNameA with DBCS.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Oct 14 09:37:29 CDT 2014


Module: wine
Branch: master
Commit: 4aea5ca72b3af995606ab4784792608637548291
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=4aea5ca72b3af995606ab4784792608637548291

Author: Akihiro Sagawa <sagawa.aki at gmail.com>
Date:   Tue Oct 14 00:24:58 2014 +0900

kernel32: Fix incorrect lastpart in GetFullPathNameA with DBCS.

---

 dlls/kernel32/path.c       | 16 ++++++----------
 dlls/kernel32/tests/path.c | 22 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/dlls/kernel32/path.c b/dlls/kernel32/path.c
index 09fb04b..c4a37b2 100644
--- a/dlls/kernel32/path.c
+++ b/dlls/kernel32/path.c
@@ -251,12 +251,12 @@ DWORD WINAPI GetFullPathNameA( LPCSTR name, DWORD len, LPSTR buffer,
                                LPSTR *lastpart )
 {
     WCHAR *nameW;
-    WCHAR bufferW[MAX_PATH];
+    WCHAR bufferW[MAX_PATH], *lastpartW = NULL;
     DWORD ret;
 
     if (!(nameW = FILE_name_AtoW( name, FALSE ))) return 0;
 
-    ret = GetFullPathNameW( nameW, MAX_PATH, bufferW, NULL);
+    ret = GetFullPathNameW( nameW, MAX_PATH, bufferW, &lastpartW);
 
     if (!ret) return 0;
     if (ret > MAX_PATH)
@@ -267,14 +267,10 @@ DWORD WINAPI GetFullPathNameA( LPCSTR name, DWORD len, LPSTR buffer,
     ret = copy_filename_WtoA( bufferW, buffer, len );
     if (ret < len && lastpart)
     {
-        LPSTR p = buffer + strlen(buffer) - 1;
-
-        if (*p != '\\')
-        {
-            while ((p > buffer + 2) && (*p != '\\')) p--;
-            *lastpart = p + 1;
-        }
-        else *lastpart = NULL;
+        if (lastpartW)
+            *lastpart = buffer + FILE_name_WtoA( bufferW, lastpartW - bufferW, NULL, 0 );
+        else
+            *lastpart = NULL;
     }
     return ret;
 }
diff --git a/dlls/kernel32/tests/path.c b/dlls/kernel32/tests/path.c
index 0f07ea6..44f14d0 100644
--- a/dlls/kernel32/tests/path.c
+++ b/dlls/kernel32/tests/path.c
@@ -1828,6 +1828,7 @@ static void test_GetFullPathNameA(void)
     char output[MAX_PATH], *filepart;
     DWORD ret;
     int i;
+    UINT acp;
 
     const struct
     {
@@ -1864,6 +1865,27 @@ static void test_GetFullPathNameA(void)
            "[%d] Expected GetLastError() to return 0xdeadbeef, got %u\n",
            i, GetLastError());
     }
+
+    acp = GetACP();
+    if (acp != 932)
+        skip("Skipping DBCS(Japanese) GetFullPathNameA test in this codepage (%d)\n", acp);
+    else {
+        const struct dbcs_case {
+            const char *input;
+            const char *expected;
+        } testset[] = {
+            { "c:\\a\\\x95\x5c\x97\xa0.txt", "\x95\x5c\x97\xa0.txt" },
+            { "c:\\\x83\x8f\x83\x43\x83\x93\\wine.c", "wine.c" },
+            { "c:\\demo\\\x97\xa0\x95\x5c", "\x97\xa0\x95\x5c" }
+        };
+        for (i = 0; i < sizeof(testset)/sizeof(testset[0]); i++) {
+            ret = GetFullPathNameA(testset[i].input, sizeof(output),
+                                   output, &filepart);
+            ok(ret, "[%d] GetFullPathName error %u\n", i, GetLastError());
+            ok(!lstrcmpA(filepart, testset[i].expected),
+               "[%d] expected %s got %s\n", i, testset[i].expected, filepart);
+        }
+    }
 }
 
 static void test_GetFullPathNameW(void)




More information about the wine-cvs mailing list