Module: wine Branch: master Commit: cdd135c2f3024835192d7fef55e3a0e9e2bbfd73 URL: http://source.winehq.org/git/wine.git/?a=commit;h=cdd135c2f3024835192d7fef55...
Author: Rob Shearman rob@codeweavers.com Date: Wed Mar 12 15:36:00 2008 +0000
wininet: Fix URLCache_LocalFileNameToPathA to return a full path, rather than just the container path.
This was caused by path_len including the nul-terminator and so the rest of the string was being added after the nul-terminator, which is incorrect. This is fixed by making path_len not include the nul-terminator.
Also fix a few other issues with the function, like not passing a correct length into the second call to WideCharToMultiByte, nRequired being calculated incorrectly and the string not always being nul-terminated.
Add a test for this function by testing the lpszLocalFileName field obtained from RetrieveUrlCacheEntryFileA.
---
dlls/wininet/tests/urlcache.c | 1 + dlls/wininet/urlcache.c | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/dlls/wininet/tests/urlcache.c b/dlls/wininet/tests/urlcache.c index 572420a..3d82caf 100644 --- a/dlls/wininet/tests/urlcache.c +++ b/dlls/wininet/tests/urlcache.c @@ -70,6 +70,7 @@ static void test_urlcacheA(void)
ok(lpCacheEntryInfo->dwStructSize == sizeof(*lpCacheEntryInfo), "lpCacheEntryInfo->dwStructSize was %d\n", lpCacheEntryInfo->dwStructSize); ok(!strcmp(lpCacheEntryInfo->lpszSourceUrlName, TEST_URL), "lpCacheEntryInfo->lpszSourceUrlName should be %s instead of %s\n", TEST_URL, lpCacheEntryInfo->lpszSourceUrlName); + ok(!strcmp(lpCacheEntryInfo->lpszLocalFileName, filename), "lpCacheEntryInfo->lpszLocalFileName should be %s instead of %s\n", filename, lpCacheEntryInfo->lpszLocalFileName);
HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
diff --git a/dlls/wininet/urlcache.c b/dlls/wininet/urlcache.c index 90c0d58..2f24b15 100644 --- a/dlls/wininet/urlcache.c +++ b/dlls/wininet/urlcache.c @@ -909,14 +909,14 @@ static BOOL URLCache_LocalFileNameToPathA( return FALSE; }
- path_len = WideCharToMultiByte(CP_ACP, 0, pContainer->path, -1, NULL, 0, NULL, NULL); - file_name_len = strlen(szLocalFileName); + path_len = WideCharToMultiByte(CP_ACP, 0, pContainer->path, -1, NULL, 0, NULL, NULL) - 1; + file_name_len = strlen(szLocalFileName) + 1 /* for nul-terminator */; dir_len = DIR_LENGTH;
- nRequired = (path_len + dir_len + 1 + file_name_len) * sizeof(WCHAR); + nRequired = (path_len + dir_len + 1 + file_name_len) * sizeof(char); if (nRequired < *lpBufferSize) { - WideCharToMultiByte(CP_ACP, 0, pContainer->path, -1, szPath, -1, NULL, NULL); + WideCharToMultiByte(CP_ACP, 0, pContainer->path, -1, szPath, path_len, NULL, NULL); memcpy(szPath+path_len, pHeader->directory_data[Directory].filename, dir_len); szPath[path_len + dir_len] = '\'; memcpy(szPath + path_len + dir_len + 1, szLocalFileName, file_name_len);