From a70ad42d224665f2a5c5989763708073ecf7443d Mon Sep 17 00:00:00 2001 From: nhmall Date: Tue, 8 Oct 2024 11:57:46 -0400 Subject: [PATCH] address Windows windsys.c analyzer complaints sys/windows/windsys.c(419): warning C6387: 'hMod' could be '0': this does not adhere to the specification for the function 'GetProcAddress'. sys/windows/windsys.c(437): warning C28159: Consider using 'GetTickCount64' instead of 'GetTickCount'. Reason: GetTickCount overflows roughly every 49 days. Code that does not take that into account can loop indefinitely. GetTickCount64 operates on 64 bit values and does not have that problem --- sys/windows/windsys.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/sys/windows/windsys.c b/sys/windows/windsys.c index 0634796b5..77d1881bf 100644 --- a/sys/windows/windsys.c +++ b/sys/windows/windsys.c @@ -416,12 +416,14 @@ static HWND GetConsoleHandle(void) { HMODULE hMod = GetModuleHandle("kernel32.dll"); - GETCONSOLEWINDOW pfnGetConsoleWindow = - (GETCONSOLEWINDOW) GetProcAddress(hMod, "GetConsoleWindow"); - if (pfnGetConsoleWindow) - return pfnGetConsoleWindow(); - else - return GetConsoleHwnd(); + + if (hMod) { + GETCONSOLEWINDOW pfnGetConsoleWindow = + (GETCONSOLEWINDOW) GetProcAddress(hMod, "GetConsoleWindow"); + if (pfnGetConsoleWindow) + return pfnGetConsoleWindow(); + } + return GetConsoleHwnd(); } static HWND @@ -434,7 +436,7 @@ GetConsoleHwnd(void) /* Get current window title */ GetConsoleTitle(OldTitle, sizeof OldTitle); - (void) sprintf(NewTitle, "NETHACK%ld/%ld", GetTickCount(), + (void) sprintf(NewTitle, "NETHACK%lld/%ld", GetTickCount64(), GetCurrentProcessId()); SetConsoleTitle(NewTitle);