From: Peter Beutner
Subject: [2/2] kernel32: properly handle double delimiters in GetShortPathName/GetLongPathName. (v3)
Message-Id: <1471205090-28997-2-git-send-email-p.beutner@gmx.net>
Date: Sun, 14 Aug 2016 22:04:50 +0200
In-Reply-To: <1471205090-28997-1-git-send-email-p.beutner@gmx.net>
References: <1471205090-28997-1-git-send-email-p.beutner@gmx.net>
v3: don't strip double delimiter as shown by tests/fix GetLongPathName as well
Fix paths starting with ".\\\\" by removing superfluous if clause.
Don't strip double delimiters.
Fixes https://bugs.winehq.org/show_bug.cgi?id=41002
Signed-off-by: Peter Beutner
---
dlls/kernel32/path.c | 27 ++-------------------------
dlls/kernel32/tests/path.c | 10 ----------
2 files changed, 2 insertions(+), 35 deletions(-)
diff --git a/dlls/kernel32/path.c b/dlls/kernel32/path.c
index 620401d..eadd2e7 100644
--- a/dlls/kernel32/path.c
+++ b/dlls/kernel32/path.c
@@ -335,23 +335,12 @@ DWORD WINAPI GetLongPathNameW( LPCWSTR shortpath, LPWSTR longpath, DWORD longlen
/* check for path delimiters and reproduce them */
if (shortpath[sp] == '\\' || shortpath[sp] == '/')
{
- if (!lp || (tmplongpath[lp-1] != '\\' && tmplongpath[lp-1] != '/'))
- {
- /* strip double delimiters */
- tmplongpath[lp++] = shortpath[sp];
- }
+ tmplongpath[lp++] = shortpath[sp++];
tmplongpath[lp] = 0; /* terminate string */
- sp++;
continue;
}
p = shortpath + sp;
- if (sp == 0 && p[0] == '.' && (p[1] == '/' || p[1] == '\\'))
- {
- tmplongpath[lp++] = *p++;
- tmplongpath[lp++] = *p++;
- sp += 2;
- }
for (; *p && *p != '/' && *p != '\\'; p++);
tmplen = p - (shortpath + sp);
lstrcpynW(tmplongpath + lp, shortpath + sp, tmplen + 1);
@@ -498,24 +487,12 @@ DWORD WINAPI GetShortPathNameW( LPCWSTR longpath, LPWSTR shortpath, DWORD shortl
/* check for path delimiters and reproduce them */
if (longpath[lp] == '\\' || longpath[lp] == '/')
{
- if (!sp || (tmpshortpath[sp-1] != '\\' && tmpshortpath[sp-1] != '/'))
- {
- /* strip double delimiters */
- tmpshortpath[sp] = longpath[lp];
- sp++;
- }
+ tmpshortpath[sp++] = longpath[lp++];
tmpshortpath[sp] = 0; /* terminate string */
- lp++;
continue;
}
p = longpath + lp;
- if (lp == 0 && p[0] == '.' && (p[1] == '/' || p[1] == '\\'))
- {
- tmpshortpath[sp++] = *p++;
- tmpshortpath[sp++] = *p++;
- lp += 2;
- }
for (; *p && *p != '/' && *p != '\\'; p++);
tmplen = p - (longpath + lp);
lstrcpynW(tmpshortpath + sp, longpath + lp, tmplen + 1);
diff --git a/dlls/kernel32/tests/path.c b/dlls/kernel32/tests/path.c
index 764141d..7eb9e75 100644
--- a/dlls/kernel32/tests/path.c
+++ b/dlls/kernel32/tests/path.c
@@ -949,31 +949,23 @@ static void test_PathNameA(CHAR *curdir, CHAR curDrive, CHAR otherDrive)
/* test double delimiters */
sprintf(tmpstr,"%s\\\\%s", SHORTDIR,SHORTFILE);
ok(GetShortPathNameA(tmpstr,tmpstr1,MAX_PATH),"GetShortPathNameA failed\n");
- todo_wine
ok(lstrcmpiA(tmpstr,tmpstr1)==0,
"GetShortPathNameA returned '%s' instead of '%s'\n",tmpstr1,tmpstr);
sprintf(tmpstr,".\\\\%s\\\\%s", SHORTDIR,SHORTFILE);
- todo_wine
- {
ok(GetShortPathNameA(tmpstr,tmpstr1,MAX_PATH),"GetShortPathNameA failed\n");
ok(lstrcmpiA(tmpstr,tmpstr1)==0,
"GetShortPathNameA returned '%s' instead of '%s'\n",tmpstr1,tmpstr);
- }
if (pGetLongPathNameA) {
sprintf(tmpstr,"%s\\\\%s",LONGDIR,LONGFILE);
ok(pGetLongPathNameA(tmpstr,tmpstr1,MAX_PATH),"GetLongPathNameA failed\n");
- todo_wine
ok(lstrcmpiA(tmpstr,tmpstr1)==0,
"GetLongPathNameA returned '%s' instead of '%s'\n",tmpstr1,tmpstr);
sprintf(tmpstr,".\\\\%s\\\\%s",LONGDIR,LONGFILE);
- todo_wine
- {
ok(pGetLongPathNameA(tmpstr,tmpstr1,MAX_PATH),"GetLongPathNameA failed\n");
ok(lstrcmpiA(tmpstr,tmpstr1)==0,
"GetLongPathNameA returned '%s' instead of '%s'\n",tmpstr1,tmpstr);
- }
}
}
@@ -2204,12 +2196,10 @@ static void test_relative_path(void)
strcpy(buf, "deadbeef");
ret = pGetLongPathNameA("..\\\\foo\\file", buf, MAX_PATH);
ok(ret, "GetLongPathName error %d\n", GetLastError());
- todo_wine
ok(!strcmp(buf, "..\\\\foo\\file"), "expected ..\\\\foo\\file, got %s\n", buf);
strcpy(buf, "deadbeef");
ret = GetShortPathNameA("..\\\\foo\\file", buf, MAX_PATH);
ok(ret, "GetShortPathName error %d\n", GetLastError());
- todo_wine
ok(!strcmp(buf, "..\\\\foo\\file"), "expected ..\\\\foo\\file, got %s\n", buf);
SetCurrentDirectoryA("..");
--
2.7.3