Commit 2a98f9b0 authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

kernel32: Make GetModuleFileName set ERROR_INSUFFICIENT_BUFFER like win2k3 and vista do.

parent bbd8ae43
......@@ -608,7 +608,10 @@ DWORD WINAPI GetModuleFileNameA(
if ((len = GetModuleFileNameW( hModule, filenameW, size )))
{
len = FILE_name_WtoA( filenameW, len, lpFileName, size );
if (len < size) lpFileName[len] = '\0';
if (len < size)
lpFileName[len] = '\0';
else
SetLastError( ERROR_INSUFFICIENT_BUFFER );
}
HeapFree( GetProcessHeap(), 0, filenameW );
return len;
......@@ -642,7 +645,10 @@ DWORD WINAPI GetModuleFileNameW( HMODULE hModule, LPWSTR lpFileName, DWORD size
{
len = min(size, pldr->FullDllName.Length / sizeof(WCHAR));
memcpy(lpFileName, pldr->FullDllName.Buffer, len * sizeof(WCHAR));
if (len < size) lpFileName[len] = '\0';
if (len < size)
lpFileName[len] = '\0';
else
SetLastError( ERROR_INSUFFICIENT_BUFFER );
}
else SetLastError( RtlNtStatusToDosError( nts ) );
......
......@@ -4657,33 +4657,32 @@ static void test_GetWindowModuleFileName(void)
hinst = GetModuleHandle(0);
/* MSDN mentions ERROR_INSUFFICIENT_BUFFER, but XP doesn't do it */
SetLastError(0xdeadbeef);
ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
ok(ret2 == ret1 - 2, "expected %u, got %u\n", ret1 - 2, ret2);
ok(GetLastError() == 0xdeadbeef ||
GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3 */
ok(GetLastError() == 0xdeadbeef /* XP */ ||
GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
"expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
SetLastError(0xdeadbeef);
ret2 = GetModuleFileName(hinst, buf2, 0);
ok(!ret2, "GetModuleFileName should return 0\n");
ok(GetLastError() == 0xdeadbeef ||
GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3 */
ok(GetLastError() == 0xdeadbeef /* XP */ ||
GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
"expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
SetLastError(0xdeadbeef);
ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
ok(ret2 == ret1 - 2, "expected %u, got %u\n", ret1 - 2, ret2);
ok(GetLastError() == 0xdeadbeef ||
GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3 */
ok(GetLastError() == 0xdeadbeef /* XP */ ||
GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
"expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
SetLastError(0xdeadbeef);
ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
ok(!ret2, "expected 0, got %u\n", ret2);
ok(GetLastError() == 0xdeadbeef ||
GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3 */
ok(GetLastError() == 0xdeadbeef /* XP */ ||
GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
"expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
DestroyWindow(hwnd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment