Skip to content

Commit 1961efe

Browse files
committed
Merge branch 'sh/mingw-safer-compat-poll'
Windows fix. * sh/mingw-safer-compat-poll: poll: use GetTickCount64() to avoid wrap-around issues
2 parents 6e31fa9 + e8dfcac commit 1961efe

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

compat/poll/poll.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
You should have received a copy of the GNU General Public License along
1919
with this program; if not, see <http://www.gnu.org/licenses/>. */
2020

21+
/* To bump the minimum Windows version to Windows Vista */
22+
#include "git-compat-util.h"
23+
2124
/* Tell gcc not to warn about the (nfd < 0) tests, below. */
2225
#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__
2326
# pragma GCC diagnostic ignored "-Wtype-limits"
@@ -449,7 +452,8 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
449452
static HANDLE hEvent;
450453
WSANETWORKEVENTS ev;
451454
HANDLE h, handle_array[FD_SETSIZE + 2];
452-
DWORD ret, wait_timeout, nhandles, start = 0, elapsed, orig_timeout = 0;
455+
DWORD ret, wait_timeout, nhandles, orig_timeout = 0;
456+
ULONGLONG start = 0;
453457
fd_set rfds, wfds, xfds;
454458
BOOL poll_again;
455459
MSG msg;
@@ -465,7 +469,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
465469
if (timeout != INFTIM)
466470
{
467471
orig_timeout = timeout;
468-
start = GetTickCount();
472+
start = GetTickCount64();
469473
}
470474

471475
if (!hEvent)
@@ -614,8 +618,8 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
614618

615619
if (!rc && orig_timeout && timeout != INFTIM)
616620
{
617-
elapsed = GetTickCount() - start;
618-
timeout = elapsed >= orig_timeout ? 0 : orig_timeout - elapsed;
621+
ULONGLONG elapsed = GetTickCount64() - start;
622+
timeout = elapsed >= orig_timeout ? 0 : (int)(orig_timeout - elapsed);
619623
}
620624

621625
if (!rc && timeout)

0 commit comments

Comments
 (0)