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'.
This commit is contained in:
Sam Lantinga
2026-03-30 10:37:09 -07:00
parent 0756603e6d
commit b878ab1691
3 changed files with 7 additions and 3 deletions

View File

@@ -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));

View File

@@ -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) {

View File

@@ -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;