Fixed buffer size handling in GetUserNameA (reported by Hannu

Valtonen).
This commit is contained in:
Alexandre Julliard 2004-05-10 21:26:58 +00:00
parent d19e264640
commit 6ddfba14e2
1 changed files with 4 additions and 2 deletions

View File

@ -55,13 +55,14 @@ GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
{
WCHAR *buffer;
BOOL ret;
DWORD sizeW = *lpSize * 2;
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, *lpSize * 2 * sizeof(WCHAR) )))
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, sizeW * sizeof(WCHAR) )))
{
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
return FALSE;
}
ret = GetUserNameW( buffer, *lpSize * 2 );
ret = GetUserNameW( buffer, &sizeW );
if (ret)
{
if (!(*lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL )))
@ -71,6 +72,7 @@ GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
ret = FALSE;
}
}
else *lpSize = sizeW * 2;
HeapFree( GetProcessHeap(), 0, buffer );
return ret;
}