Skip to content

Commit

Permalink
Various static analysis fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaldaien committed Dec 20, 2024
1 parent 00992f5 commit b18cc6f
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 196 deletions.
2 changes: 1 addition & 1 deletion include/SpecialK/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions include/SpecialK/render/dxgi/dxgi_swapchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down Expand Up @@ -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 ) );
Expand Down
138 changes: 3 additions & 135 deletions include/SpecialK/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,118 +323,7 @@ class SK_WASAPI_EndPointManager : public IMMNotificationClient
{
}

void Activate (void)
{
std::scoped_lock <SK_Thread_HybridSpinlock> lock0 (activation_lock_);

try
{
SK_ComPtr <IMMDeviceEnumerator> pDevEnum;

ThrowIfFailed (
pDevEnum.CoCreateInstance (__uuidof (MMDeviceEnumerator)));

SK_RunOnce (
pDevEnum->RegisterEndpointNotificationCallback (this)
);

SK_ComPtr <IMMDeviceCollection> 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 <IMMDevice> 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 <IPropertyStore> 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 <void **>(&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)
{
Expand Down Expand Up @@ -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 <SK_WASAPI_AudioSession*> sessions_;
Expand Down
4 changes: 3 additions & 1 deletion include/SpecialK/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 <InstructionSet_Internal> ()); }
static void deferredInit (void);

private:
static std::unique_ptr <InstructionSet_Internal> CPU_Rep;
Expand Down
28 changes: 12 additions & 16 deletions include/imgui/imgui_user.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 ",
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 ())
Expand Down
14 changes: 8 additions & 6 deletions src/framerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <double> (cur) / 10000.0;
Expand Down Expand Up @@ -1129,8 +1129,9 @@ SK_Framerate_WaitForVBlank (void)
}
}

#if 1
return true;

#else
// D3D10/11/12
SK_ComQIPtr <IDXGISwapChain> dxgi_swap (rb.swapchain);
SK_ComPtr <IDXGIOutput> dxgi_output = nullptr;
Expand Down Expand Up @@ -1193,8 +1194,8 @@ SK_Framerate_WaitForVBlank (void)
}
}

return false;
#endif
}

void
Expand Down Expand Up @@ -1237,9 +1238,11 @@ SK_D3DKMT_WaitForVBlank (void)

SK_Framerate_WaitForVBlank ();

#if 1
return;

#else
SK_Framerate_WaitForVBlank2 ();
#endif
};

LONG64 __SK_VBlankLatency_QPCycles;
Expand Down Expand Up @@ -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;
Expand Down
21 changes: 15 additions & 6 deletions src/ini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ iSK_INI::iSK_INI (const wchar_t* filename)
{
encoding_ = INI_UTF8;

AddRef ();
this->iSK_INI::AddRef ();

SK_ReleaseAssert (
filename != nullptr);
Expand All @@ -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?

Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -490,6 +496,9 @@ Import_Section ( iSK_INISection &section,
wchar_t *end,
SK_TLS **ppTLS = nullptr )
{
if (start == nullptr || end == nullptr)
return false;

SK_TLS *pTLS = nullptr;

if ( ppTLS != nullptr &&
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion src/injection/injection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
Loading

0 comments on commit b18cc6f

Please sign in to comment.