From 4aea5ca72b3af995606ab4784792608637548291 Mon Sep 17 00:00:00 2001 From: Akihiro Sagawa Date: Tue, 14 Oct 2014 00:24:58 +0900 Subject: [PATCH] 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 09fb04be335..c4a37b20bb5 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 0f07ea6fb01..44f14d011aa 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)