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.
This commit is contained in:
Rob Shearman 2008-03-12 15:36:00 +00:00 committed by Alexandre Julliard
parent c46279ced7
commit cdd135c2f3
2 changed files with 5 additions and 4 deletions

View File

@ -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);

View File

@ -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);