From 6c6bf9e4e6e36c1fc49d70b5e925e571607acf02 Mon Sep 17 00:00:00 2001 From: Selva Nair Date: Tue, 17 Jan 2023 15:36:31 -0500 Subject: [PATCH] Bugfix AutoCloseHandler(): accommodate wraparound of 32 bit time - GetTickcount() and current-time passed-in to the callback are both 32 bit which wraps around every ~50 days. In the stop condition compare the elasped ticks and timeout value instead of end-time and now. The latter can wraparound in a long-running process. Signed-off-by: Selva Nair --- openvpn.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openvpn.c b/openvpn.c index bfe01eb..bf8fb1c 100644 --- a/openvpn.c +++ b/openvpn.c @@ -453,15 +453,15 @@ AutoCloseHandler(HWND hwnd, UINT UNUSED msg, UINT_PTR id, DWORD now) if (!ac) return; - UINT end = ac->start + ac->timeout; - if (now >= end) + DWORD elapsed = now - ac->start; + if (elapsed >= ac->timeout) { SimulateButtonPress(hwnd, ac->btn); AutoCloseCancel(hwnd); } else { - SetDlgItemText(hwnd, ac->txtid, LoadLocalizedString(ac->txtres, (end - now)/1000)); + SetDlgItemText(hwnd, ac->txtid, LoadLocalizedString(ac->txtres, (ac->timeout - elapsed)/1000)); SetTimer(hwnd, id, 500, AutoCloseHandler); } }