diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 1bcff894620..932483325c8 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -4868,7 +4868,7 @@ INT WINAPI WSAAddressToStringW( LPSOCKADDR sockaddr, DWORD len, p = strchrW( buffer, ':' ); if (!((SOCKADDR_IN *)sockaddr)->sin_port) *p = 0; - size = strlenW( buffer ); + size = strlenW( buffer ) + 1; if (*lenstr < size) { @@ -4876,6 +4876,7 @@ INT WINAPI WSAAddressToStringW( LPSOCKADDR sockaddr, DWORD len, return SOCKET_ERROR; } + *lenstr = size; lstrcpyW( string, buffer ); return 0; } diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index eb76a8651ea..cd88b8dd25d 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -1369,6 +1369,7 @@ static void test_WSAAddressToStringW(void) ok( !ret, "WSAAddressToStringW() failed unexpectedly: %d\n", WSAGetLastError() ); ok( !lstrcmpW( address, expect1 ), "Expected different address string\n" ); + ok( len == sizeof( expect1 )/sizeof( WCHAR ), "Expected size to be %d, got %d\n", sizeof( expect1 )/sizeof( WCHAR ), len); len = sizeof(address); @@ -1402,6 +1403,7 @@ static void test_WSAAddressToStringW(void) ok( !ret, "WSAAddressToStringW() failed unexpectedly: %d\n", WSAGetLastError() ); ok( !lstrcmpW( address, expect4 ), "Expected different address string\n" ); + ok( len == sizeof( expect4 )/sizeof( WCHAR ), "Expected size to be %d, got %d\n", sizeof( expect4 )/sizeof( WCHAR ), len); } static void test_WSAStringToAddressA(void)