Skip to content

Commit e2b5b4f

Browse files
committed
Various static analysis fix-ups applied. (Hopefully nothing broke!)
1 parent 7d992a6 commit e2b5b4f

15 files changed

Lines changed: 153 additions & 88 deletions

File tree

CHANGELOG.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
26.4.18
1+
26.4.18.1
2+
=========
3+
+ Switch ImGui's ImHash (...) function to use Special K's SSE4.2 crc32c
4+
algorithm instead of its slower lookup table.
5+
+ Various static analysis fix-ups applied. (Hopefully nothing broke!)
6+
7+
26.4.18
28
=======
39
+ Block gamepad input to games while the Alt-Tab application switcher
410
is visible and covering the game (since gamepads now control it).

include/SpecialK/DLL_VERSION.H

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#define SK_YEAR 26
44
#define SK_MONTH 4
55
#define SK_DATE 18
6-
#define SK_REV_N 0
7-
#define SK_REV 0
6+
#define SK_REV_N 1
7+
#define SK_REV 1
88

99
#ifndef _A2
1010
#define _A2(a) #a

include/SpecialK/render/dxgi/dxgi_backend.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,36 @@ HRESULT SK_DXGI_GetDebugInterface (REFIID riid, void** ppDebug);
512512
HRESULT SK_DXGI_OutputDebugString (const std::string& str, DXGI_INFO_QUEUE_MESSAGE_SEVERITY severity);
513513
HRESULT SK_DXGI_ReportLiveObjects (IUnknown* pDev = nullptr);
514514

515+
// Account for padding in the structure, and test for equality using this operator
516+
// instead of using memcmp (...).
517+
static inline bool operator== (const DXGI_SWAP_CHAIN_DESC& lhs,
518+
const DXGI_SWAP_CHAIN_DESC& rhs) noexcept
519+
{
520+
// Good lord! C++20 could do this automatically... but we're not using it.
521+
return
522+
lhs.BufferDesc.Width == rhs.BufferDesc.Width &&
523+
lhs.BufferDesc.Height == rhs.BufferDesc.Height &&
524+
lhs.BufferDesc.RefreshRate.Numerator == rhs.BufferDesc.RefreshRate.Numerator &&
525+
lhs.BufferDesc.RefreshRate.Denominator == rhs.BufferDesc.RefreshRate.Denominator &&
526+
lhs.BufferDesc.Format == rhs.BufferDesc.Format &&
527+
lhs.BufferDesc.Scaling == rhs.BufferDesc.Scaling &&
528+
lhs.BufferDesc.ScanlineOrdering == rhs.BufferDesc.ScanlineOrdering &&
529+
lhs.SampleDesc.Count == rhs.SampleDesc.Count &&
530+
lhs.SampleDesc.Quality == rhs.SampleDesc.Quality &&
531+
lhs.BufferUsage == rhs.BufferUsage &&
532+
lhs.BufferCount == rhs.BufferCount &&
533+
lhs.OutputWindow == rhs.OutputWindow &&
534+
lhs.Windowed == rhs.Windowed &&
535+
lhs.SwapEffect == rhs.SwapEffect &&
536+
lhs.Flags == rhs.Flags;
537+
}
538+
539+
static inline bool operator!= (const DXGI_SWAP_CHAIN_DESC& lhs,
540+
const DXGI_SWAP_CHAIN_DESC& rhs) noexcept
541+
{
542+
return
543+
!(lhs == rhs);
544+
}
515545

516546
static constexpr
517547
BOOL

src/control_panel/cfg_input.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,12 @@ SK::ControlPanel::Input::Draw (void)
791791
ImGui::PushStyleColor (ImGuiCol_FrameBgActive, ImVec4 ( 0.9f, 0.9f, 0.9f, val));
792792
ImGui::PushStyleColor (ImGuiCol_SliderGrab, ImVec4 ( 1.0f, 1.0f, 1.0f, 1.0f));
793793

794+
bool disable_cursor_autohide_ui = false;
794795
if (!cursor_manage || !allow_show_cursor)
795-
SK_ImGui_BeginDisabled ();
796+
{
797+
disable_cursor_autohide_ui = true;
798+
SK_ImGui_BeginDisabled ();
799+
}
796800
ImGui::PushItemWidth (button_size.x);
797801
if ( ImGui::SliderFloat ("###SecondsBeforeHidingCursor",
798802
&seconds, 0.0f, 10.0f, seconds > 0.0 ? "%.2f Second Idle" : "Always Hidden" ) )
@@ -810,7 +814,7 @@ SK::ControlPanel::Input::Draw (void)
810814
(
811815
"Auto-hide the cursor in response to XInput (Xbox) or HID (PlayStation) input activity."
812816
);
813-
if (!cursor_manage || !allow_show_cursor)
817+
if (disable_cursor_autohide_ui)
814818
SK_ImGui_EndDisabled();
815819
ImGui::SameLine ( );
816820
ImGui::TreePop ( );

src/input/cursor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,9 +1204,9 @@ GetCursorPos_Detour (LPPOINT lpPoint)
12041204
if (lpPoint == nullptr)
12051205
return FALSE;
12061206

1207-
if ( auto fixed_return = GetCursorPos_GameSpecificFixes (lpPoint);
1208-
fixed_return.has_value () )
1209-
return fixed_return. value ();
1207+
if ( auto fixed_return = GetCursorPos_GameSpecificFixes (lpPoint);
1208+
fixed_return.has_value () )
1209+
return *fixed_return;
12101210

12111211
//
12121212
// Allow games running as a background window with Continue Rendering enabled

src/input/game_input.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ SK_IWrapGameInput::GetNextReading (_In_ IGameInputReading *referenceRea
502502
if (SUCCEEDED (hr) && reading_ != nullptr)
503503
{
504504
if (reading != nullptr)
505-
{ *reading = (IGameInputReading *)new SK_IWrapGameInputReading (reading_);
505+
{ *reading = (IGameInputReading *)new (std::nothrow) SK_IWrapGameInputReading (reading_);
506506
_current_readings [device][inputKind] = *reading;
507507

508508
SK_GameInput_EmulatedPlayStation = false;

src/nvapi.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ NVAPI::FindGPUByDXGIName (const wchar_t* wszName)
316316
//"NVIDIA "
317317
// 01234567
318318

319-
wchar_t* wszFixedName = _wcsdup (wszName + 7);
319+
wchar_t* wszFixedName = _wcsdup (wszName + 7);
320320
int fixed_len = lstrlenW (wszFixedName);
321321

322322
if (wszFixedName != nullptr)
@@ -713,7 +713,7 @@ NvAPI_Disp_HdrColorControl_Override ( NvU32 displayId,
713713
if (pHdrColorData->version == NV_HDR_COLOR_DATA_VER1)
714714
{
715715
NV_HDR_COLOR_DATA_V1 origData = *((NV_HDR_COLOR_DATA_V1 *)pHdrColorData);
716-
memcpy (&expandedData, &origData, sizeof (NV_HDR_COLOR_DATA_V1));
716+
memcpy (&expandedData, &origData, sizeof (NV_HDR_COLOR_DATA_V1)); //-V512_UNDERFLOW_OFF
717717

718718
expandedData.version = NV_HDR_COLOR_DATA_VER2;
719719
pHdrColorData = &expandedData;

src/render/d3d11/d3d11.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6415,7 +6415,7 @@ D3D11Dev_CreateTexture2DCore_Impl (
64156415
resample_job_s resample = { };
64166416
resample.time.preprocess = SK_QueryPerf ().QuadPart;
64176417

6418-
auto* image = new DirectX::ScratchImage;
6418+
auto* image = new (std::nothrow) DirectX::ScratchImage;
64196419
image->Initialize (mdata);
64206420

64216421
bool error = false;
@@ -6482,7 +6482,7 @@ D3D11Dev_CreateTexture2DCore_Impl (
64826482
if (config.textures.d3d11.uncompressed_mips && compressed)
64836483
{
64846484
auto* decompressed =
6485-
new DirectX::ScratchImage;
6485+
new (std::nothrow) DirectX::ScratchImage;
64866486

64876487
ret =
64886488
DirectX::Decompress (orig_img, 1, image->GetMetadata (), DXGI_FORMAT_UNKNOWN, *decompressed);

src/render/dxgi/dxgi.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,7 +2777,7 @@ SK_DXGI_PresentBase ( IDXGISwapChain *This,
27772777

27782778
const bool bDLSS3OnVRRDisplay =
27792779
__SK_IsDLSSGActive && tearing_override.has_value () ?
2780-
!tearing_override. value () : false;
2780+
!*tearing_override : false;
27812781

27822782
auto _Present = [&](UINT _SyncInterval,
27832783
UINT _Flags) ->
@@ -2870,8 +2870,8 @@ SK_DXGI_PresentBase ( IDXGISwapChain *This,
28702870
if (! bDLSS3OnVRRDisplay)
28712871
{
28722872
// Need tearing override for other reasons...
2873-
if ( tearing_override.has_value ())
2874-
{ if (tearing_override. value ())
2873+
if ( tearing_override.has_value ())
2874+
{ if (*tearing_override)
28752875
{
28762876
_SyncInterval = 0;
28772877
_Flags |= (DXGI_PRESENT_ALLOW_TEARING | DXGI_PRESENT_RESTART);
@@ -5951,7 +5951,7 @@ SK_DXGI_CreateSwapChain_PreInit (
59515951

59525952
_ORIGINAL_SWAP_CHAIN_DESC = orig_desc;
59535953

5954-
if (pDesc != nullptr && memcmp (&orig_desc, pDesc, sizeof (DXGI_SWAP_CHAIN_DESC)) != 0)
5954+
if (pDesc != nullptr && orig_desc != *pDesc)
59555955
{
59565956
_DescribeSwapChain (L"SPECIAL K OVERRIDES APPLIED");
59575957
}

src/steam/steam_api.cpp

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2774,12 +2774,19 @@ class SK_Steam_AchievementManager : public SK_AchievementManager
27742774
if ( achievement == nullptr ||
27752775
achievement->name_.empty () )
27762776
{
2777-
achievement = new
2777+
// If this fails, we're leaking memory.
2778+
SK_ReleaseAssert (achievement == nullptr);
2779+
2780+
achievement = new (std::nothrow)
27782781
Achievement (i,
27792782
stats->GetAchievementName (i),
27802783
stats
27812784
);
27822785

2786+
// Out of memory?!
2787+
if (achievement == nullptr)
2788+
continue;
2789+
27832790
achievements.list [i] =
27842791
achievement;
27852792
achievements.string_map [achievement->name_] =
@@ -3781,6 +3788,9 @@ SK_Steam_GetLibraries (steam_library_t** ppLibraries)
37813788
dwSize =
37823789
GetFileSize (hLibFolders, &dwSizeHigh);
37833790

3791+
// A 4 GiB manifest file would be insane, so log it :)
3792+
SK_ReleaseAssert (dwSizeHigh == 0 && "Manifest Too Large!");
3793+
37843794
std::unique_ptr <char []>
37853795
local_data;
37863796
char* data = nullptr;
@@ -6430,12 +6440,14 @@ __stdcall
64306440
SK_SteamOverlay_GoToURL ( const char* szURL,
64316441
bool bUseWindowsShellIfOverlayFails )
64326442
{
6433-
if ( steam_ctx.Utils () != nullptr &&
6434-
steam_ctx.Utils ()->IsOverlayEnabled () )
6443+
auto utils = steam_ctx.Utils ();
6444+
if ( utils != nullptr &&
6445+
utils->IsOverlayEnabled () )
64356446
{
6436-
if (steam_ctx.Friends () != nullptr)
6447+
auto friends = steam_ctx.Friends ();
6448+
if ( friends != nullptr )
64376449
{
6438-
steam_ctx.Friends ()->ActivateGameOverlayToWebPage (szURL);
6450+
friends->ActivateGameOverlayToWebPage (szURL);
64396451
return true;
64406452
}
64416453
}
@@ -6454,12 +6466,14 @@ bool
64546466
__stdcall
64556467
SK_SteamOverlay_GoToFriendProfile (CSteamID friend_sid)
64566468
{
6457-
if ( steam_ctx.Utils () != nullptr &&
6458-
steam_ctx.Utils ()->IsOverlayEnabled () )
6469+
auto utils = steam_ctx.Utils ();
6470+
if ( utils != nullptr &&
6471+
utils->IsOverlayEnabled () )
64596472
{
6460-
if (steam_ctx.Friends () != nullptr)
6473+
auto friends = steam_ctx.Friends ();
6474+
if ( friends != nullptr )
64616475
{
6462-
steam_ctx.Friends ()->ActivateGameOverlayToUser (
6476+
friends->ActivateGameOverlayToUser (
64636477
"steamid", friend_sid
64646478
);
64656479

@@ -6474,12 +6488,14 @@ bool
64746488
__stdcall
64756489
SK_SteamOverlay_GoToFriendAchievements (CSteamID friend_sid)
64766490
{
6477-
if ( steam_ctx.Utils () != nullptr &&
6478-
steam_ctx.Utils ()->IsOverlayEnabled () )
6491+
auto utils = steam_ctx.Utils ();
6492+
if ( utils != nullptr &&
6493+
utils->IsOverlayEnabled () )
64796494
{
6480-
if (steam_ctx.Friends () != nullptr)
6495+
auto friends = steam_ctx.Friends ();
6496+
if ( friends != nullptr )
64816497
{
6482-
steam_ctx.Friends ()->ActivateGameOverlayToUser (
6498+
friends->ActivateGameOverlayToUser (
64836499
"achievements", friend_sid
64846500
);
64856501

@@ -6494,12 +6510,14 @@ bool
64946510
__stdcall
64956511
SK_SteamOverlay_GoToFriendStats (CSteamID friend_sid)
64966512
{
6497-
if ( steam_ctx.Utils () != nullptr &&
6498-
steam_ctx.Utils ()->IsOverlayEnabled () )
6513+
auto utils = steam_ctx.Utils ();
6514+
if ( utils != nullptr &&
6515+
utils->IsOverlayEnabled () )
64996516
{
6500-
if (steam_ctx.Friends () != nullptr)
6517+
auto friends = steam_ctx.Friends ();
6518+
if ( friends != nullptr)
65016519
{
6502-
steam_ctx.Friends ()->ActivateGameOverlayToUser (
6520+
friends->ActivateGameOverlayToUser (
65036521
"stats", friend_sid
65046522
);
65056523

0 commit comments

Comments
 (0)