kernel32: Fix GetComputerNameA to not count trailing NULL, with test.
This commit is contained in:
parent
f279252189
commit
81c922398e
|
@ -371,7 +371,7 @@ out:
|
|||
BOOL WINAPI GetComputerNameA(LPSTR name, LPDWORD size)
|
||||
{
|
||||
WCHAR nameW[ MAX_COMPUTERNAME_LENGTH + 1 ];
|
||||
DWORD sizeW = MAX_COMPUTERNAME_LENGTH;
|
||||
DWORD sizeW = MAX_COMPUTERNAME_LENGTH + 1;
|
||||
unsigned int len;
|
||||
BOOL ret;
|
||||
|
||||
|
@ -381,17 +381,16 @@ BOOL WINAPI GetComputerNameA(LPSTR name, LPDWORD size)
|
|||
/* for compatibility with Win9x */
|
||||
__TRY
|
||||
{
|
||||
if ( *size < len + 1 )
|
||||
if ( *size < len )
|
||||
{
|
||||
*size = len + 1;
|
||||
*size = len;
|
||||
SetLastError( ERROR_MORE_DATA );
|
||||
ret = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
WideCharToMultiByte ( CP_ACP, 0, nameW, -1, name, len, NULL, 0 );
|
||||
name[len] = 0;
|
||||
*size = len;
|
||||
*size = len - 1;
|
||||
ret = TRUE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -239,6 +239,7 @@ static void test_GetComputerName(void)
|
|||
LPSTR name;
|
||||
LPWSTR nameW;
|
||||
DWORD error;
|
||||
int name_len;
|
||||
|
||||
size = 0;
|
||||
ret = GetComputerNameA((LPSTR)0xdeadbeef, &size);
|
||||
|
@ -250,6 +251,16 @@ static void test_GetComputerName(void)
|
|||
ok(ret, "GetComputerNameA failed with error %d\n", GetLastError());
|
||||
HeapFree(GetProcessHeap(), 0, name);
|
||||
|
||||
size = MAX_COMPUTERNAME_LENGTH + 1;
|
||||
name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
|
||||
ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
|
||||
ret = GetComputerNameA(name, &size);
|
||||
ok(ret, "GetComputerNameA failed with error %d\n", GetLastError());
|
||||
trace("computer name is \"%s\"\n", name);
|
||||
name_len = strlen(name);
|
||||
ok(size == name_len, "size should be same as length, name_len=%d, size=%d\n", name_len, size);
|
||||
HeapFree(GetProcessHeap(), 0, name);
|
||||
|
||||
size = 0;
|
||||
ret = GetComputerNameW((LPWSTR)0xdeadbeef, &size);
|
||||
error = GetLastError();
|
||||
|
|
Loading…
Reference in New Issue