diff --git a/src/backend/port/win32/socket.c b/src/backend/port/win32/socket.c
index 9c339397d1..18dc8d9686 100644
--- a/src/backend/port/win32/socket.c
+++ b/src/backend/port/win32/socket.c
@@ -519,8 +519,8 @@ pgwin32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, c
 										 * different from writefds, so
 										 * 2*FD_SETSIZE sockets */
 	SOCKET		sockets[FD_SETSIZE * 2];
-	int			numevents = 0;
-	int			i;
+	u_int		numevents = 0;
+	u_int		i;
 	int			r;
 	DWORD		timeoutval = WSA_INFINITE;
 	FD_SET		outreadfds;
@@ -618,7 +618,7 @@ pgwin32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, c
 		{
 			TranslateSocketError();
 			/* release already-assigned event objects */
-			while (--i >= 0)
+			while (i-- >= 0)
 				WSAEventSelect(sockets[i], NULL, 0);
 			for (i = 0; i < numevents; i++)
 				WSACloseEvent(events[i]);