فهرست منبع

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)
Sam Lantinga 2 روز پیش
والد
کامیت
3c9510f2ce
3فایلهای تغییر یافته به همراه7 افزوده شده و 3 حذف شده
  1. 4 0
      src/stdlib/SDL_string.c
  2. 1 0
      src/video/windows/SDL_windowsevents.c
  3. 2 3
      src/video/windows/SDL_windowskeyboard.c

+ 4 - 0
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)
 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;
     char *fmt_utf8 = NULL;
     if (fmt) {
     if (fmt) {
         fmt_utf8 = SDL_iconv_string("UTF-8", "WCHAR_T", (const char *)fmt, (SDL_wcslen(fmt) + 1) * sizeof(wchar_t));
         fmt_utf8 = SDL_iconv_string("UTF-8", "WCHAR_T", (const char *)fmt, (SDL_wcslen(fmt) + 1) * sizeof(wchar_t));

+ 1 - 0
src/video/windows/SDL_windowsevents.c

@@ -901,6 +901,7 @@ static char *GetDeviceName(HANDLE hDevice, HDEVINFO devinfo, const char *instanc
 
 
     if (hid_loaded) {
     if (hid_loaded) {
         char devName[MAX_PATH + 1];
         char devName[MAX_PATH + 1];
+        devName[0] = '\0';
         UINT cap = sizeof(devName) - 1;
         UINT cap = sizeof(devName) - 1;
         UINT len = GetRawInputDeviceInfoA(hDevice, RIDI_DEVICENAME, devName, &cap);
         UINT len = GetRawInputDeviceInfoA(hDevice, RIDI_DEVICENAME, devName, &cap);
         if (len != (UINT)-1) {
         if (len != (UINT)-1) {

+ 2 - 3
src/video/windows/SDL_windowskeyboard.c

@@ -599,7 +599,6 @@ static DWORD IME_GetId(SDL_VideoData *videodata, UINT uIndex)
     static HKL hklprev = 0;
     static HKL hklprev = 0;
     static DWORD dwRet[2] = { 0 };
     static DWORD dwRet[2] = { 0 };
     DWORD dwVerSize = 0;
     DWORD dwVerSize = 0;
-    DWORD dwVerHandle = 0;
     LPVOID lpVerBuffer = 0;
     LPVOID lpVerBuffer = 0;
     LPVOID lpVerData = 0;
     LPVOID lpVerData = 0;
     UINT cbVerData = 0;
     UINT cbVerData = 0;
@@ -637,11 +636,11 @@ static DWORD IME_GetId(SDL_VideoData *videodata, UINT uIndex)
             return dwRet[0];
             return dwRet[0];
         }
         }
 #undef LCID_INVARIANT
 #undef LCID_INVARIANT
-        dwVerSize = GetFileVersionInfoSizeA(szTemp, &dwVerHandle);
+        dwVerSize = GetFileVersionInfoSizeA(szTemp, NULL);
         if (dwVerSize) {
         if (dwVerSize) {
             lpVerBuffer = SDL_malloc(dwVerSize);
             lpVerBuffer = SDL_malloc(dwVerSize);
             if (lpVerBuffer) {
             if (lpVerBuffer) {
-                if (GetFileVersionInfoA(szTemp, dwVerHandle, dwVerSize, lpVerBuffer)) {
+                if (GetFileVersionInfoA(szTemp, 0, dwVerSize, lpVerBuffer)) {
                     if (VerQueryValueA(lpVerBuffer, "\\", &lpVerData, &cbVerData)) {
                     if (VerQueryValueA(lpVerBuffer, "\\", &lpVerData, &cbVerData)) {
 #define pVerFixedInfo ((VS_FIXEDFILEINFO FAR *)lpVerData)
 #define pVerFixedInfo ((VS_FIXEDFILEINFO FAR *)lpVerData)
                         DWORD dwVer = pVerFixedInfo->dwFileVersionMS;
                         DWORD dwVer = pVerFixedInfo->dwFileVersionMS;