From b18cc6f015ce786ffd022d20f6678a1f7ebcd51c Mon Sep 17 00:00:00 2001 From: Kaldaien Date: Fri, 20 Dec 2024 06:06:18 -0500 Subject: [PATCH] Various static analysis fixes --- include/SpecialK/config.h | 2 +- include/SpecialK/render/dxgi/dxgi_swapchain.h | 4 +- include/SpecialK/sound.h | 138 +---------------- include/SpecialK/utility.h | 4 +- include/imgui/imgui_user.inl | 28 ++-- src/framerate.cpp | 14 +- src/ini.cpp | 21 ++- src/injection/injection.cpp | 3 +- src/render/screenshot.cpp | 28 ++-- src/sound.cpp | 140 ++++++++++++++++++ src/utility.cpp | 22 +-- 11 files changed, 208 insertions(+), 196 deletions(-) diff --git a/include/SpecialK/config.h b/include/SpecialK/config.h index 38687c1d2..3f70982d2 100644 --- a/include/SpecialK/config.h +++ b/include/SpecialK/config.h @@ -168,7 +168,7 @@ struct sk_config_t { cpu_pop = 0; - for ( DWORD_PTR i = 0 ; i < SK_GetBitness () ; ++i ) + for ( DWORD_PTR i = 0 ; i < (DWORD_PTR)SK_GetBitness () ; ++i ) { if ((process_affinity >> i) & 0x1) ++cpu_pop; diff --git a/include/SpecialK/render/dxgi/dxgi_swapchain.h b/include/SpecialK/render/dxgi/dxgi_swapchain.h index a4fc4e7ea..9f1ebc975 100644 --- a/include/SpecialK/render/dxgi/dxgi_swapchain.h +++ b/include/SpecialK/render/dxgi/dxgi_swapchain.h @@ -125,7 +125,7 @@ IWrapDXGISwapChain : IDXGISwapChain4 sd.SwapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL ); flip_model.native = rb.active_traits.bOriginallyFlip; - SetPrivateDataInterface (IID_IUnwrappedDXGISwapChain, pReal); + this->IWrapDXGISwapChain::SetPrivateDataInterface (IID_IUnwrappedDXGISwapChain, pReal); SK_DXGI_SetDebugName ( pReal, SK_FormatStringW ( L"SK_IWrapDXGISwapChain: pReal=%p", pReal ) ); @@ -244,7 +244,7 @@ IWrapDXGISwapChain : IDXGISwapChain4 sd.SwapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL ); flip_model.native = rb.active_traits.bOriginallyFlip; - SetPrivateDataInterface (IID_IUnwrappedDXGISwapChain, pReal); + this->IWrapDXGISwapChain::SetPrivateDataInterface (IID_IUnwrappedDXGISwapChain, pReal); SK_DXGI_SetDebugName ( pReal, SK_FormatStringW ( L"SK_IWrapDXGISwapChain: pReal=%p", pReal ) ); diff --git a/include/SpecialK/sound.h b/include/SpecialK/sound.h index 31bff58fc..19bebe16b 100644 --- a/include/SpecialK/sound.h +++ b/include/SpecialK/sound.h @@ -323,118 +323,7 @@ class SK_WASAPI_EndPointManager : public IMMNotificationClient { } - void Activate (void) - { - std::scoped_lock lock0 (activation_lock_); - - try - { - SK_ComPtr pDevEnum; - - ThrowIfFailed ( - pDevEnum.CoCreateInstance (__uuidof (MMDeviceEnumerator))); - - SK_RunOnce ( - pDevEnum->RegisterEndpointNotificationCallback (this) - ); - - SK_ComPtr dev_collection; - ThrowIfFailed ( - pDevEnum->EnumAudioEndpoints (eRender, DEVICE_STATE_ACTIVE, &dev_collection.p)); - - if (dev_collection.p != nullptr) - { - UINT uiDevices = 0; - ThrowIfFailed ( - dev_collection->GetCount (&uiDevices)); - - for ( UINT i = 0 ; i < uiDevices ; ++i ) - { - SK_MMDev_Endpoint endpoint; - - SK_ComPtr pDevice; - ThrowIfFailed ( - dev_collection->Item (i, &pDevice.p)); - - if (pDevice.p != nullptr) - { - wchar_t* wszId = nullptr; - ThrowIfFailed ( - pDevice->GetId (&wszId)); - - auto _FindRenderDevice = [&](const wchar_t *device_id) -> SK_MMDev_Endpoint * - { - for ( auto& device : render_devices_ ) - { - if (device.id_._Equal (device_id)) - return &device; - } - - return nullptr; - }; - - if (wszId != nullptr && !_FindRenderDevice (wszId)) - { - SK_ComPtr props; - ThrowIfFailed ( - pDevice->OpenPropertyStore (STGM_READ, &props.p)); - - if (props.p != nullptr) - { - PROPVARIANT propvarName; - PropVariantInit (&propvarName); - - ThrowIfFailed ( - props->GetValue (PKEY_Device_FriendlyName, &propvarName)); - - endpoint.flow_ = eRender; - endpoint.id_ = wszId; - endpoint.name_ = SK_WideCharToUTF8 (propvarName.pwszVal); - endpoint.device_ = pDevice; - - ThrowIfFailed ( - pDevice->GetState (&endpoint.state_)); - - PropVariantClear (&propvarName); - - if (FAILED (pDevice->Activate ( - __uuidof (IAudioSessionManager2), - CLSCTX_ALL, - nullptr, - reinterpret_cast (&endpoint.control_.sessions) - ) ) ) return; - - endpoint.control_.meter.Attach ( - SK_WASAPI_GetAudioMeterInfo (pDevice).Detach () - ); - - endpoint.control_.volume.Attach (SK_MMDev_GetEndpointVolumeControl (pDevice).Detach ()); - endpoint.control_.auto_gain.Attach (SK_MMDev_GetAutoGainControl (pDevice).Detach ()); - endpoint.control_.loudness. Attach (SK_MMDev_GetLoudness (pDevice).Detach ()); - endpoint.control_.audio_client.Attach (SK_WASAPI_GetAudioClient (pDevice).Detach ()); - - endpoint.control_.sessions->RegisterSessionNotification (&endpoint); - - render_devices_.emplace_back (endpoint); - } - - CoTaskMemFree (wszId); - } - } - } - } - //pDevEnum->EnumAudioEndpoints (eCapture, DEVICE_STATEMASK_ALL, &dev_collection.p); - } - - catch (const std::exception& e) - { - SK_LOG0 ( ( L"%ws (...) Failed " - L"During Endpoint Enumeration : %hs", __FUNCTIONW__, e.what () - ),L" WASAPI " ); - - return; - } - } + void Activate (void); bool initAudioPolicyConfigFactory (void) { @@ -1073,29 +962,8 @@ class SK_WASAPI_SessionManager inactive_sessions_.view.clear (); } - void AddSession (SK_WASAPI_AudioSession *pSession, AudioSessionState state) - { - bool new_session = - sessions_.emplace (pSession).second; - - SK_ReleaseAssert (new_session); - - SetSessionState (pSession, state); - } - - void RemoveSession (SK_WASAPI_AudioSession* pSession) - { - if (! pSession) - return; - - SetSessionState (pSession, AudioSessionStateExpired); - - if (sessions_.count (pSession)) - { - sessions_.erase (pSession); - pSession->Release (); - } - } + void AddSession (SK_WASAPI_AudioSession *pSession, AudioSessionState state); + void RemoveSession (SK_WASAPI_AudioSession *pSession); private: std::set sessions_; diff --git a/include/SpecialK/utility.h b/include/SpecialK/utility.h index 5920068a2..afb1ead19 100644 --- a/include/SpecialK/utility.h +++ b/include/SpecialK/utility.h @@ -328,6 +328,8 @@ extern void WINAPI SK_ExitProcess ( UINT uExitCode ) noexcep extern void WINAPI SK_ExitThread ( DWORD dwExitCode ) noexcept; extern BOOL WINAPI SK_TerminateThread ( HANDLE hThread, DWORD dwExitCode ) noexcept; +extern BOOL WINAPI SK_TerminatePID ( DWORD dwProcessId, + UINT uExitCode ) noexcept; extern BOOL WINAPI SK_TerminateProcess ( HANDLE hProcess, UINT uExitCode ) noexcept; extern BOOL WINAPI SK_TerminateProcesses ( const wchar_t* wszProcName, @@ -866,7 +868,7 @@ class InstructionSet static bool _3DNOW (void) { return CPU_Rep->isAMD_ && CPU_Rep->f_81_EDX_ [31]; } - static void deferredInit (void) { SK_RunOnce (CPU_Rep = std::make_unique ()); } + static void deferredInit (void); private: static std::unique_ptr CPU_Rep; diff --git a/include/imgui/imgui_user.inl b/include/imgui/imgui_user.inl index 1b2d748ec..d3679bcec 100644 --- a/include/imgui/imgui_user.inl +++ b/include/imgui/imgui_user.inl @@ -272,7 +272,7 @@ SK_ImGui_ProcessRawInput ( _In_ HRAWINPUT hRawInput, { case RID_INPUT: size = - pRawCtx->cached_input.Data->header.dwSize; + pRawCtx->cached_input.Data [0].header.dwSize; break; case RID_HEADER: @@ -343,15 +343,12 @@ SK_ImGui_ProcessRawInput ( _In_ HRAWINPUT hRawInput, if (uiCommand == RID_HEADER) size = sizeof (RAWINPUTHEADER); - if (pData != nullptr) + if ( *pcbSize >= size) + memcpy (pData, pRawCtx->cached_input.Data, size); + else { - if ( *pcbSize >= size) - memcpy (pData, pRawCtx->cached_input.Data, size); - else - { - SetLastError (ERROR_INSUFFICIENT_BUFFER); - return ~0U; - } + SetLastError (ERROR_INSUFFICIENT_BUFFER); + return ~0U; } SK_LOGs1 ( L" RawInput ", @@ -1077,8 +1074,8 @@ ImGui_WndProcHandler ( HWND hWnd, UINT msg, { //SK_LOG0 ( (L"ImGui Witnessed WM_SETCURSOR"), L"Window Mgr" ); - if ( LOWORD (lParam) == HTCLIENT || - LOWORD (lParam) == HTTRANSPARENT ) + if ( LOWORD (lParam) == (WORD)HTCLIENT || + LOWORD (lParam) == (WORD)HTTRANSPARENT ) { static POINTS lastMouse = { SHORT_MAX, SHORT_MAX }; @@ -1815,8 +1812,7 @@ SK_ImGui_PollGamepad_EndFrame (XINPUT_STATE* pState) pLastActiveController = &ps_controller; } - if ( config.input.gamepad.xinput.ui_slot >= 0 && - config.input.gamepad.xinput.ui_slot < 4 ) + if (config.input.gamepad.xinput.ui_slot < 4) { // Use the HID data to control the UI bHasPlayStation = true; } @@ -3544,9 +3540,9 @@ SK_ImGui_User_NewFrame (void) SK_ImGui_Cursor.idle = false; else - SK_ImGui_Cursor.idle = ( (! bWantMouseCaptureForUI) || config.input.mouse.disabled_to_game == SK_InputEnablement::Disabled ); - // Disabled to game is a form of capture, - // but it is exempt from idle cursor logic + SK_ImGui_Cursor.idle = ( config.input.mouse.disabled_to_game == SK_InputEnablement::Disabled ); + // Disabled to game is a form of capture, + // but it is exempt from idle cursor logic // When first opening the control panel, keep the cursor visible longer than usual if (SK_ImGui_Cursor.last_toggle > SK::ControlPanel::current_time - 3333UL && SK_ImGui_Active ()) diff --git a/src/framerate.cpp b/src/framerate.cpp index 138ea4fb5..e69d53371 100644 --- a/src/framerate.cpp +++ b/src/framerate.cpp @@ -926,7 +926,7 @@ SK::Framerate::Init (void) ULONG min, max, cur; if ( NtQueryTimerResolution (&min, &max, &cur) == - STATUS_SUCCESS && _SetTimerResolution != nullptr ) + STATUS_SUCCESS ) { dTimerRes = static_cast (cur) / 10000.0; @@ -1129,8 +1129,9 @@ SK_Framerate_WaitForVBlank (void) } } +#if 1 return true; - +#else // D3D10/11/12 SK_ComQIPtr dxgi_swap (rb.swapchain); SK_ComPtr dxgi_output = nullptr; @@ -1193,8 +1194,8 @@ SK_Framerate_WaitForVBlank (void) } } - return false; +#endif } void @@ -1237,9 +1238,11 @@ SK_D3DKMT_WaitForVBlank (void) SK_Framerate_WaitForVBlank (); +#if 1 return; - +#else SK_Framerate_WaitForVBlank2 (); +#endif }; LONG64 __SK_VBlankLatency_QPCycles; @@ -2154,8 +2157,7 @@ SK::Framerate::Limiter::wait (void) ((qpc_t1.QuadPart - qpc_t0.QuadPart) / ticks_per_scanline) <= _MARGIN) { if (( getScanLine.ScanLine <= (_MARGIN/3) || - getScanLine.ScanLine >= scanlines - ((_MARGIN / (_MARGIN/2)) * _MARGIN) ) && - getScanLine.InVerticalBlank) + getScanLine.ScanLine >= scanlines - ((_MARGIN / (_MARGIN/2)) * _MARGIN) )) { if (getScanLine.ScanLine < scanline_t0) getScanLine.ScanLine += scanlines; diff --git a/src/ini.cpp b/src/ini.cpp index a976da013..b86f4abbf 100644 --- a/src/ini.cpp +++ b/src/ini.cpp @@ -342,7 +342,7 @@ iSK_INI::iSK_INI (const wchar_t* filename) { encoding_ = INI_UTF8; - AddRef (); + this->iSK_INI::AddRef (); SK_ReleaseAssert ( filename != nullptr); @@ -361,13 +361,13 @@ iSK_INI::iSK_INI (const wchar_t* filename) SK_StripTrailingSlashesW (name.data ()); - reload (); + this->iSK_INI::reload (); } iSK_INI::~iSK_INI (void) { ULONG refs = - Release (); + this->iSK_INI::Release (); SK_ReleaseAssert (refs == 0); // Memory leak? @@ -409,6 +409,12 @@ Process_Section ( iSK_INISection &kSection, wchar_t *end, SK_TLS **ppTLS = nullptr ) { + if (start == nullptr || end == nullptr) + { + static iSK_INISection nul_section = {}; + return nul_section; + } + SK_TLS *pTLS = nullptr; if ( ppTLS != nullptr && @@ -490,6 +496,9 @@ Import_Section ( iSK_INISection §ion, wchar_t *end, SK_TLS **ppTLS = nullptr ) { + if (start == nullptr || end == nullptr) + return false; + SK_TLS *pTLS = nullptr; if ( ppTLS != nullptr && @@ -640,7 +649,7 @@ iSK_INI::parse (void) else break; } - if (SK_CharNextW (pNext) != nullptr) + if (SK_CharNextW (pNext) != nullptr && pEnd != nullptr) { ZeroMemory (pEnd, (SK_CharNextW (pNext) - pEnd) * sizeof (*pEnd)); @@ -841,7 +850,7 @@ iSK_INI::import (const wchar_t* import_data) else break; } - if (SK_CharNextW (pNext) != nullptr) + if (SK_CharNextW (pNext) != nullptr && pEnd != nullptr) { ZeroMemory (pEnd, (SK_CharNextW (pNext) - pEnd) * sizeof (*pEnd)); @@ -1150,7 +1159,7 @@ __stdcall iSK_INISection::add_key_value (const std::wstring& key, const std::wstring& value) { const auto add = - keys.emplace (std::make_pair (key, value)); + keys.try_emplace (key, value); if (add.second) { diff --git a/src/injection/injection.cpp b/src/injection/injection.cpp index 84c22d8bd..c58ed5cb5 100644 --- a/src/injection/injection.cpp +++ b/src/injection/injection.cpp @@ -1454,7 +1454,8 @@ CBTProc ( _In_ int nCode, } BOOL -SK_TerminatePID ( DWORD dwProcessId, UINT uExitCode ) +WINAPI +SK_TerminatePID ( DWORD dwProcessId, UINT uExitCode ) noexcept { SK_AutoHandle hProcess ( OpenProcess ( PROCESS_TERMINATE, FALSE, dwProcessId ) diff --git a/src/render/screenshot.cpp b/src/render/screenshot.cpp index 8dd1f6be8..8937143d7 100644 --- a/src/render/screenshot.cpp +++ b/src/render/screenshot.cpp @@ -855,7 +855,7 @@ SK_Screenshot_SaveAVIF (DirectX::ScratchImage &src_image, const wchar_t *wszFile uint32_t height = sk::narrow_cast (metadata.height); int bit_depth = 10; - avifPixelFormat yuv_format = AVIF_PIXEL_FORMAT_YUV444; + avifPixelFormat yuv_format = AVIF_PIXEL_FORMAT_NONE; switch (config.screenshots.avif.yuv_subsampling) { @@ -990,7 +990,7 @@ SK_Screenshot_SaveAVIF (DirectX::ScratchImage &src_image, const wchar_t *wszFile encoder = SK_avifEncoderCreate (); - if (encoder != nullptr) + if (encoder != nullptr && image != nullptr) { encoder->quality = std::clamp (config.screenshots.compression_quality, AVIF_QUALITY_WORST, AVIF_QUALITY_BEST); encoder->qualityAlpha = std::clamp (config.screenshots.compression_quality, AVIF_QUALITY_WORST, AVIF_QUALITY_BEST); @@ -999,8 +999,7 @@ SK_Screenshot_SaveAVIF (DirectX::ScratchImage &src_image, const wchar_t *wszFile encoder->maxThreads = config.screenshots.avif.max_threads; encoder->speed = config.screenshots.avif.compression_speed; encoder->minQuantizer = AVIF_QUANTIZER_BEST_QUALITY; - encoder->maxQuantizer = encoder->quality == AVIF_QUALITY_LOSSLESS ? AVIF_QUANTIZER_LOSSLESS : - (int)((100.0f - (float)encoder->quality) * 63.0f); + encoder->maxQuantizer = AVIF_QUANTIZER_WORST_QUALITY; encoder->codecChoice = AVIF_CODEC_CHOICE_AUTO; image->clli.maxCLL = max_cll; @@ -1018,7 +1017,7 @@ SK_Screenshot_SaveAVIF (DirectX::ScratchImage &src_image, const wchar_t *wszFile SK_LOGi0 (L"rgbToYUV: %d, addImage: %d, encode: %d", rgbToYuvResult, addResult, encodeResult); } - if (encodeResult == AVIF_RESULT_OK) + if (encodeResult == AVIF_RESULT_OK && avifOutput.data != nullptr) { wchar_t wszAVIFPath [MAX_PATH + 2] = { }; wcsncpy_s (wszAVIFPath, wszFilePath, MAX_PATH); @@ -1519,7 +1518,7 @@ SK_WIC_SetBasicMetadata (IWICMetadataQueryWriter *pMQW) if (*szName != '\0') { - char* names [] = { szName }; + static char* names [] = { szName }; value.vt = VT_VECTOR | VT_LPSTR; value.calpstr.cElems = 1; @@ -2327,9 +2326,7 @@ SK_Image_DispatchTonemapJobs (std::vector & jobs) Rec709toICtCp (value); float Y_in = std::max (XMVectorGetX (ICtCp), 0.0f); - float Y_out = 1.0f; - - Y_out = + float Y_out = TonemapHDR (Y_in, pJob->maxYInPQ, pJob->SDR_YInPQ); if (Y_out + Y_in > 0.0f) @@ -2388,15 +2385,18 @@ SK_Image_EnqueueTonemapTask ( DirectX::ScratchImage& image, float maxLuminance, float sdrLuminance) { + const auto& metadata = + image.GetMetadata (); + for ( auto i = 0; i < config.screenshots.avif.max_threads; ++i ) { - size_t iStartRow = (image.GetMetadata ().height / config.screenshots.avif.max_threads) * i; - size_t iEndRow = (image.GetMetadata ().height / config.screenshots.avif.max_threads) * (i + 1); + size_t iStartRow = (metadata.height / config.screenshots.avif.max_threads) * i; + size_t iEndRow = (metadata.height / config.screenshots.avif.max_threads) * (i + 1); jobs [i].pFirstPixel = - &pixels [iStartRow * image.GetMetadata ().width]; + &pixels [iStartRow * metadata.width]; jobs [i].pLastPixel = - &pixels [iEndRow * image.GetMetadata ().width - 1]; + &pixels [iEndRow * metadata.width - 1]; jobs [i].maxYInPQ = maxLuminance; jobs [i].SDR_YInPQ = sdrLuminance; @@ -2790,7 +2790,7 @@ SK_Screenshot_SaveUHDR (const DirectX::Image& image, const DirectX::Image& sdr_i //sk_uhdr_get_decoded_image //sk_uhdr_get_gain_map_image (decoder) - auto metadata = + const auto metadata = sk_uhdr_dec_get_gain_map_metadata (decoder); SK_LOGi0 (L"UltraHDR Min/Max Content Boost: %fx / %fx", metadata->min_content_boost, metadata->max_content_boost); diff --git a/src/sound.cpp b/src/sound.cpp index 5845ac2e5..5bac884ee 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -1342,4 +1342,144 @@ SK_WASAPI_SessionManager::getMeterInfo (void) return SK_WASAPI_GetAudioMeterInfo (pDefaultDevice); +} + +void +SK_WASAPI_EndPointManager::Activate (void) +{ + std::scoped_lock lock0 (activation_lock_); + + try + { + SK_ComPtr pDevEnum; + + ThrowIfFailed ( + pDevEnum.CoCreateInstance (__uuidof (MMDeviceEnumerator))); + + SK_RunOnce ( + pDevEnum->RegisterEndpointNotificationCallback (this) + ); + + SK_ComPtr dev_collection; + ThrowIfFailed ( + pDevEnum->EnumAudioEndpoints (eRender, DEVICE_STATE_ACTIVE, &dev_collection.p)); + + if (dev_collection.p != nullptr) + { + UINT uiDevices = 0; + ThrowIfFailed ( + dev_collection->GetCount (&uiDevices)); + + for ( UINT i = 0 ; i < uiDevices ; ++i ) + { + SK_MMDev_Endpoint endpoint; + + SK_ComPtr pDevice; + ThrowIfFailed ( + dev_collection->Item (i, &pDevice.p)); + + if (pDevice.p != nullptr) + { + wchar_t* wszId = nullptr; + ThrowIfFailed ( + pDevice->GetId (&wszId)); + + auto _FindRenderDevice = [&](const wchar_t *device_id) -> SK_MMDev_Endpoint * + { + for ( auto& device : render_devices_ ) + { + if (device.id_._Equal (device_id)) + return &device; + } + + return nullptr; + }; + + if (wszId != nullptr && !_FindRenderDevice (wszId)) + { + SK_ComPtr props; + ThrowIfFailed ( + pDevice->OpenPropertyStore (STGM_READ, &props.p)); + + if (props.p != nullptr) + { + PROPVARIANT propvarName; + PropVariantInit (&propvarName); + + ThrowIfFailed ( + props->GetValue (PKEY_Device_FriendlyName, &propvarName)); + + endpoint.flow_ = eRender; + endpoint.id_ = wszId; + endpoint.name_ = SK_WideCharToUTF8 (propvarName.pwszVal); + endpoint.device_ = pDevice; + + ThrowIfFailed ( + pDevice->GetState (&endpoint.state_)); + + PropVariantClear (&propvarName); + + if (FAILED (pDevice->Activate ( + __uuidof (IAudioSessionManager2), + CLSCTX_ALL, + nullptr, + reinterpret_cast (&endpoint.control_.sessions) + ) ) ) return; + + endpoint.control_.meter.Attach ( + SK_WASAPI_GetAudioMeterInfo (pDevice).Detach () + ); + + endpoint.control_.volume.Attach (SK_MMDev_GetEndpointVolumeControl (pDevice).Detach ()); + endpoint.control_.auto_gain.Attach (SK_MMDev_GetAutoGainControl (pDevice).Detach ()); + endpoint.control_.loudness. Attach (SK_MMDev_GetLoudness (pDevice).Detach ()); + endpoint.control_.audio_client.Attach (SK_WASAPI_GetAudioClient (pDevice).Detach ()); + + endpoint.control_.sessions->RegisterSessionNotification (&endpoint); + + render_devices_.emplace_back (endpoint); + } + + CoTaskMemFree (wszId); + } + } + } + } + //pDevEnum->EnumAudioEndpoints (eCapture, DEVICE_STATEMASK_ALL, &dev_collection.p); + } + + catch (const std::exception& e) + { + SK_LOG0 ( ( L"%ws (...) Failed " + L"During Endpoint Enumeration : %hs", __FUNCTIONW__, e.what () + ),L" WASAPI " ); + + return; + } +} + +void +SK_WASAPI_SessionManager::AddSession (SK_WASAPI_AudioSession *pSession, AudioSessionState state) +{ + const bool new_session = + sessions_.emplace (pSession).second; + + SK_ReleaseAssert (new_session); + + SetSessionState (pSession, state); +} + +void +SK_WASAPI_SessionManager::RemoveSession (SK_WASAPI_AudioSession *pSession) +{ + if (! pSession) + return; + + SetSessionState (pSession, AudioSessionStateExpired); + + if (sessions_.count (pSession)) + { + sessions_.erase (pSession); + pSession->Release (); + } } \ No newline at end of file diff --git a/src/utility.cpp b/src/utility.cpp index 637a3e2fb..4f6f19079 100644 --- a/src/utility.cpp +++ b/src/utility.cpp @@ -1,7 +1,4 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check it. -// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: https://pvs-studio.com - -/** +/** * This file is part of Special K. * * Special K is free software : you can redistribute it @@ -736,11 +733,9 @@ SK_TerminateProcesses (const wchar_t* wszProcName, bool all) noexcept pe32.szExeFile ) ) { - BOOL SK_TerminatePID (DWORD dwProcessId, UINT uExitCode); - killed |= SK_TerminatePID (pe32.th32ProcessID, 0x0); - if (!all && killed) + if ((! all) && killed) { return TRUE; } @@ -2020,8 +2015,7 @@ SK_Assert_SameDLLVersion ( const wchar_t* wszTestFile0, } } - return (! wszVerStr0.empty ()) && - wszVerStr0._Equal (wszVerStr1); + return wszVerStr0._Equal (wszVerStr1); }; std::wstring @@ -2925,6 +2919,9 @@ SK_IsSuperSpecialK (void) void SK_PathRemoveExtension (wchar_t* wszInOut) { + if (wszInOut == nullptr) + return; + wchar_t *wszEnd = wszInOut, *wszPrev; @@ -5758,12 +5755,9 @@ SK_CharNextA (const char *szInput, int n) if (n == 1) [[likely]] return CharNextA (szNext); - if (n >= 2) + for ( int i = 0 ; i < n/2 ; ++i ) { - for ( int i = 0 ; i < n/2 ; ++i ) - { - szNext = CharNextA (CharNextA (szNext)); - } + szNext = CharNextA (CharNextA (szNext)); } if (n % 2 != 0)