From 3c9510f2ced1b5ef7c16fdac64cc3d3253bd6620 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 30 Mar 2026 10:37:09 -0700
Subject: [PATCH] Fix msvc analyzer warnings
- Initialize some out variables that are annotated inout in the function setting them.
- Fix 'dwVerHandle' might not be '0' warning from msvc analyzer calling GetFileVersionInfoA. MSDN says that
the lpdwHandle param to GetFileVersionInfoSize is optional (set to zero) and the dwHandle param to
GetFileVersionInfoA is ignored. msvc goes a step further and explicitly warns if dwHandle is not provably 0.
Fixes the following:
SDL3\src\stdlib\SDL_string.c(2359): warning C6054: String 'text' might not be zero-terminated.
SDL3\src\video\windows\SDL_windowsevents.c(897): warning C6001: Using uninitialized memory 'devName'.
SDL3\src\video\windows\SDL_windowskeyboard.c(644): warning C6388: 'dwVerHandle' might not be '0': this does not adhere to the specification for the function 'GetFileVersionInfoA'.
(cherry picked from commit b878ab16910924ca93f0048e48a34f44dfb54357)
---
src/stdlib/SDL_string.c | 4 ++++
src/video/windows/SDL_windowsevents.c | 1 +
src/video/windows/SDL_windowskeyboard.c | 5 ++---
3 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c
index 7f43025fc91e2..4a870f6e0d67f 100644
--- a/src/stdlib/SDL_string.c
+++ b/src/stdlib/SDL_string.c
@@ -2358,6 +2358,10 @@ int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FO
int SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, const wchar_t *fmt, va_list ap)
{
+ if (text) {
+ text[0] = 0;
+ }
+
char *fmt_utf8 = NULL;
if (fmt) {
fmt_utf8 = SDL_iconv_string("UTF-8", "WCHAR_T", (const char *)fmt, (SDL_wcslen(fmt) + 1) * sizeof(wchar_t));
diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index e8d971cefd9b2..282d52c0d8c8e 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -901,6 +901,7 @@ static char *GetDeviceName(HANDLE hDevice, HDEVINFO devinfo, const char *instanc
if (hid_loaded) {
char devName[MAX_PATH + 1];
+ devName[0] = '\0';
UINT cap = sizeof(devName) - 1;
UINT len = GetRawInputDeviceInfoA(hDevice, RIDI_DEVICENAME, devName, &cap);
if (len != (UINT)-1) {
diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c
index 42fb066c42a65..67cae22e5592d 100644
--- a/src/video/windows/SDL_windowskeyboard.c
+++ b/src/video/windows/SDL_windowskeyboard.c
@@ -599,7 +599,6 @@ static DWORD IME_GetId(SDL_VideoData *videodata, UINT uIndex)
static HKL hklprev = 0;
static DWORD dwRet[2] = { 0 };
DWORD dwVerSize = 0;
- DWORD dwVerHandle = 0;
LPVOID lpVerBuffer = 0;
LPVOID lpVerData = 0;
UINT cbVerData = 0;
@@ -637,11 +636,11 @@ static DWORD IME_GetId(SDL_VideoData *videodata, UINT uIndex)
return dwRet[0];
}
#undef LCID_INVARIANT
- dwVerSize = GetFileVersionInfoSizeA(szTemp, &dwVerHandle);
+ dwVerSize = GetFileVersionInfoSizeA(szTemp, NULL);
if (dwVerSize) {
lpVerBuffer = SDL_malloc(dwVerSize);
if (lpVerBuffer) {
- if (GetFileVersionInfoA(szTemp, dwVerHandle, dwVerSize, lpVerBuffer)) {
+ if (GetFileVersionInfoA(szTemp, 0, dwVerSize, lpVerBuffer)) {
if (VerQueryValueA(lpVerBuffer, "\\", &lpVerData, &cbVerData)) {
#define pVerFixedInfo ((VS_FIXEDFILEINFO FAR *)lpVerData)
DWORD dwVer = pVerFixedInfo->dwFileVersionMS;