]> repos.lx-s.de Git - winmute.git/commitdiff
Fixed some analyzer warnings
authorlx-s <lx-s@users.noreply.github.com>
Tue, 19 Dec 2023 06:43:57 +0000 (07:43 +0100)
committerlx-s <lx-s@users.noreply.github.com>
Tue, 19 Dec 2023 06:43:57 +0000 (07:43 +0100)
WinMute/AboutDlg.cpp
WinMute/BluetoothDetector.cpp
WinMute/MMNotificationClient.cpp
WinMute/SettingsDlg.cpp
WinMute/WMLog.cpp
WinMute/WMLog.h
WinMute/WMi18n.cpp
WinMute/common.h
WinMute/libs/json.hpp

index 87d5fa4411017fa9c70a4e20341886454d529117..bc2bb7702745ac779b63331dab233cb9355cef5b 100644 (file)
@@ -180,7 +180,11 @@ static INT_PTR CALLBACK About_GeneralDlgProc(HWND hDlg, UINT msg, WPARAM, LPARAM
       return TRUE;
    case WM_NOTIFY: {
       const PNMLINK pNmLink = reinterpret_cast<PNMLINK>(lParam);
-      if (pNmLink->hdr.code == NM_CLICK || pNmLink->hdr.code == NM_RETURN) {
+#pragma warning(push)
+#pragma warning(disable : 26454) // Disable arithmetic overflow warning for NM_CLICK and NM_RETURN
+      if (pNmLink->hdr.code == NM_CLICK ||
+          pNmLink->hdr.code == NM_RETURN) {
+#pragma warning(pop)
          const UINT_PTR ctrlId = pNmLink->hdr.idFrom;
          const LITEM item = pNmLink->item;
          if ((ctrlId == IDC_LINK_HOMEPAGE
@@ -296,8 +300,10 @@ INT_PTR CALLBACK AboutDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
    }
    case WM_NOTIFY: {
       const LPNMHDR lpnmhdr = reinterpret_cast<LPNMHDR>(lParam);
-      if (lpnmhdr->code == TCN_SELCHANGE
-         && lpnmhdr->hwndFrom == dlgData->hTabCtrl) {
+#pragma warning(push)
+#pragma warning(disable : 26454) // Disable arithmetic overflow for TCN_SELCHANGE
+      if (lpnmhdr->code == TCN_SELCHANGE && lpnmhdr->hwndFrom == dlgData->hTabCtrl) {
+#pragma warning(pop)
          const int curSel = TabCtrl_GetCurSel(dlgData->hTabCtrl);
          if (curSel >= 0 && curSel < ABOUT_TAB_COUNT) {
             SwitchTab(dlgData, dlgData->hTabs[curSel]);
index 7991162c97f5a3d9f65853bde504e42d6e9906c3..580e47c954ce03c092f89cee602831d0671c84c2 100644 (file)
@@ -158,7 +158,7 @@ BluetoothDetector::BluetoothStatus BluetoothDetector::GetBluetoothStatus(
    if (useDeviceList_) {
       auto pos = std::find(begin(deviceNames_), end(deviceNames_), inRangeInfo->deviceInfo.name);
       if (pos == end(deviceNames_)) {
-         log.Write(L"Bluetooth device \"S\" not in list.", inRangeInfo->deviceInfo.name);
+         log.Write(L"Bluetooth device \"%S\" not in list.", inRangeInfo->deviceInfo.name);
          return BluetoothStatus::Unknown;
       }
    }
index 31c874027a0243b70ccd72ecc5aa928237ede25d..529f175e0f27d60017f7dfc21158bf72f9765370 100644 (file)
@@ -90,7 +90,7 @@ HRESULT STDMETHODCALLTYPE MMNotificationClient::OnDeviceAdded(LPCWSTR pwstrDevic
 {
    if (notifyParent_ && pwstrDeviceId != nullptr) {
       const auto deviceName = GetFriendlyDeviceName(pwstrDeviceId);
-      WMLog::GetInstance().GetInstance().Write(L"Device \"%S\" added", deviceName.c_str());
+      WMLog::GetInstance().GetInstance().Write(L"Device \"%s\" added", deviceName.c_str());
       notifyParent_->ShouldReInit();
    }
    return S_OK;
@@ -100,7 +100,7 @@ HRESULT STDMETHODCALLTYPE MMNotificationClient::OnDeviceRemoved(LPCWSTR pwstrDev
 {
    if (notifyParent_ && pwstrDeviceId != nullptr) {
       const auto deviceName = GetFriendlyDeviceName(pwstrDeviceId);
-      WMLog::GetInstance().GetInstance().Write(L"Device \"%S\" removed", deviceName.c_str());
+      WMLog::GetInstance().GetInstance().Write(L"Device \"%s\" removed", deviceName.c_str());
       notifyParent_->ShouldReInit();
    }
    return S_OK;
index e8135528c392b6f2e0533aaf6f52ea034b108e43..4e9eb7796a8f58a35efd62e2061cbe2b8eb41aeb 100644 (file)
@@ -220,8 +220,10 @@ INT_PTR CALLBACK SettingsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lPar
       return 0;
    case WM_NOTIFY: {
       const LPNMHDR lpnmhdr = reinterpret_cast<LPNMHDR>(lParam);
-      if (lpnmhdr->code == TCN_SELCHANGE
-          && lpnmhdr->hwndFrom == dlgData->hTabCtrl) {
+#pragma warning(push)
+#pragma warning(disable : 26454) // Disable arithmetic overflow warning for TCN_SELCHANGE
+      if (lpnmhdr->code == TCN_SELCHANGE && lpnmhdr->hwndFrom == dlgData->hTabCtrl) {
+#pragma warning(pop)
          const int curSel = TabCtrl_GetCurSel(dlgData->hTabCtrl);
          if (curSel >= 0 && curSel < SETTINGS_TAB_COUNT) {
             SwitchTab(dlgData, dlgData->hTabs[curSel]);
index be90b75dad9450ee93e742c8f4b9fc2332c29ff5..9e15a0779cbf72ba95e4f10005d1a05896070fa0 100644 (file)
@@ -118,7 +118,7 @@ void WMLog::WriteMessage(const wchar_t* msg)
    logFile_.flush();
 }
 
-void WMLog::Write(const wchar_t *fmt, ...)
+void WMLog::Write(_In_z_ _Printf_format_string_ const wchar_t *fmt, ...)
 {
    if (!enabled_) {
       return;
index 08c0229b60c2b461adad23d092e54f50c80a3a28..3d56c145ec4d92afb660b949feef6cba6a98c22b 100644 (file)
@@ -39,7 +39,7 @@ class WMLog {
 public:
    static WMLog& GetInstance();
 
-   void Write(const wchar_t* fmt, ...);
+   void Write(_In_z_ _Printf_format_string_ const wchar_t* fmt, ...);
    void WriteWindowsError(const wchar_t *functionName, DWORD errorCode = -1);
 
    void SetEnabled(bool enable);
index 8a6b3d27fde1bee5cd4aa81469fc38233351ec72..3a68f1983ae3f4e22053cd3e1f2095a2ce36d09e 100644 (file)
@@ -119,7 +119,7 @@ std::vector<LanguageModule> WMi18n::GetAvailableLanguages() const
                   langDlls.push_back(langMod);
                }
             } catch (const nlohmann::json::parse_error &pe) {
-               WMLog::GetInstance().Write(L"Failed to parse language file \"%ls\": %s", wfd.cFileName, pe.what());
+               WMLog::GetInstance().Write(L"Failed to parse language file \"%ls\": %S", wfd.cFileName, pe.what());
             }
          } while (FindNextFileW(hFindFile, &wfd));
       }
@@ -179,11 +179,11 @@ bool WMi18n::LoadLanguage(const std::wstring &fileName, TranslationMap &strings)
          }
          const auto value = ConvertStringToWideString(it.value());
          if (value == L"") {
-            log.Write(L"Unable to convert language element \"%s\"", it.key().c_str());
+            log.Write(L"Unable to convert language element \"%S\"", it.key().c_str());
             return false;
          }
          if (translations_temp.contains(it.key())) {
-            log.Write(L"Double entry for language key \"%s\" found.", it.key().c_str());
+            log.Write(L"Double entry for language key \"%S\" found.", it.key().c_str());
             return false;
          }
          translations_temp[it.key()] = value;
@@ -191,7 +191,7 @@ bool WMi18n::LoadLanguage(const std::wstring &fileName, TranslationMap &strings)
       strings = std::move(translations_temp);
    } catch (const nlohmann::json::parse_error &pe) {
       WMLog::GetInstance().Write(
-         L"Failed to parse language file \"%ls\": %s",
+         L"Failed to parse language file \"%ls\": %S",
          langFilePath->filename().c_str(),
          pe.what());
       return false;
index eb2d32702f40d9de9b4ccdd1b9455f67ed78502c..57f6da80971b65c0c195d3b9a9e01d342072c1a4 100644 (file)
@@ -94,6 +94,7 @@ namespace fs = std::filesystem;
 #include <wlanapi.h>
 #include <Mmdeviceapi.h>
 #include <dwmapi.h>
+#include <sal.h>
 #pragma warning(disable : 4201)
 #  include <endpointvolume.h>
 #pragma warning(default : 4201)
index 8b72ea6539f40e4e3f7762d17e30c67f2a8308ed..4d4c89c9d9d64344e81149d8ff0faba9763a5f7e 100644 (file)
@@ -8235,7 +8235,7 @@ class lexer : public lexer_base<BasicJsonType>
                     }
                 }
             }
-
+            [[fallthrough]];
             // multi-line comments skip input until */ is read
             case '*':
             {
@@ -8269,8 +8269,9 @@ class lexer : public lexer_base<BasicJsonType>
                             continue;
                     }
                 }
+                [[fallthrough]];
             }
-
+            
             // unexpected character after reading '/'
             default:
             {