From 72f31df60fd483aa03a2bb4df3dd8c9315f50ab0 Mon Sep 17 00:00:00 2001 From: Jamiras Date: Sat, 2 Dec 2023 12:18:48 -0700 Subject: [PATCH] address analysis warnings --- src/services/AchievementRuntime.cpp | 40 ++++++++++++++-------- src/services/impl/WindowsHttpRequester.cpp | 6 ++-- src/ui/drawing/gdi/GDISurface.cpp | 2 +- src/ui/drawing/gdi/ImageRepository.cpp | 1 + 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/services/AchievementRuntime.cpp b/src/services/AchievementRuntime.cpp index f70d393b..c6e589d2 100644 --- a/src/services/AchievementRuntime.cpp +++ b/src/services/AchievementRuntime.cpp @@ -2317,7 +2317,7 @@ int AchievementRuntime::SaveProgressToBuffer(uint8_t* pBuffer, int nBufferSize) class AchievementRuntimeExports : private AchievementRuntime { public: - static void destroy() + static void destroy() noexcept { memset(&s_callbacks, 0, sizeof(s_callbacks)); } @@ -2432,6 +2432,7 @@ class AchievementRuntimeExports : private AchievementRuntime const char* password, rc_client_callback_t callback, void* callback_userdata) { + GSL_SUPPRESS_R3 auto* pCallbackData = new CallbackWrapper(client, callback, callback_userdata); auto& pClient = ra::services::ServiceLocator::GetMutable(); @@ -2476,6 +2477,7 @@ class AchievementRuntimeExports : private AchievementRuntime static rc_client_async_handle_t* begin_load_game(rc_client_t* client, const char* hash, rc_client_callback_t callback, void* callback_userdata) { + GSL_SUPPRESS_R3 auto* pCallbackData = new CallbackWrapper(client, callback, callback_userdata); auto& pClient = ra::services::ServiceLocator::GetMutable(); @@ -2510,6 +2512,7 @@ class AchievementRuntimeExports : private AchievementRuntime const uint8_t* data, size_t data_size, rc_client_callback_t callback, void* callback_userdata) { + GSL_SUPPRESS_R3 auto* pCallbackData = new CallbackWrapper(client, callback, callback_userdata); auto& pClient = ra::services::ServiceLocator::GetMutable(); @@ -2519,8 +2522,9 @@ class AchievementRuntimeExports : private AchievementRuntime static rc_client_achievement_list_info_t* create_achievement_list(int category, int grouping) { auto& pClient = ra::services::ServiceLocator::GetMutable(); - auto* list = (rc_client_achievement_list_info_t*) - rc_client_create_achievement_list(pClient.GetClient(), category, grouping); + GSL_SUPPRESS_TYPE1 + auto* list = reinterpret_cast( + rc_client_create_achievement_list(pClient.GetClient(), category, grouping)); list->destroy_func = destroy_achievement_list; return list; } @@ -2540,8 +2544,9 @@ class AchievementRuntimeExports : private AchievementRuntime static rc_client_leaderboard_list_info_t* create_leaderboard_list(int grouping) { auto& pClient = ra::services::ServiceLocator::GetMutable(); - auto* list = (rc_client_leaderboard_list_info_t*) - rc_client_create_leaderboard_list(pClient.GetClient(), grouping); + GSL_SUPPRESS_TYPE1 + auto* list = reinterpret_cast( + rc_client_create_leaderboard_list(pClient.GetClient(), grouping)); list->destroy_func = destroy_leaderboard_list; return list; } @@ -2580,7 +2585,10 @@ class AchievementRuntimeExports : private AchievementRuntime Expects(wrapper != nullptr); if (pList) - ((rc_client_leaderboard_entry_list_info_t*)pList)->destroy_func = destroy_leaderboard_entry_list; + { + GSL_SUPPRESS_TYPE1 + reinterpret_cast(pList)->destroy_func = destroy_leaderboard_entry_list; + } wrapper->DoCallback(nResult, pList, sErrorMessage); @@ -2598,6 +2606,7 @@ class AchievementRuntimeExports : private AchievementRuntime uint32_t leaderboard_id, uint32_t first_entry, uint32_t count, rc_client_fetch_leaderboard_entries_callback_t callback, void* callback_userdata) { + GSL_SUPPRESS_R3 auto* pCallbackData = new LeaderboardEntriesListCallbackWrapper(client, callback, callback_userdata); auto& pClient = ra::services::ServiceLocator::GetMutable(); @@ -2609,6 +2618,7 @@ class AchievementRuntimeExports : private AchievementRuntime uint32_t leaderboard_id, uint32_t count, rc_client_fetch_leaderboard_entries_callback_t callback, void* callback_userdata) { + GSL_SUPPRESS_R3 auto* pCallbackData = new LeaderboardEntriesListCallbackWrapper(client, callback, callback_userdata); auto& pClient = ra::services::ServiceLocator::GetMutable(); @@ -2628,7 +2638,7 @@ class AchievementRuntimeExports : private AchievementRuntime return rc_client_has_rich_presence(pClient.GetClient()); } - static void do_frame() + static void do_frame() noexcept { _RA_DoAchievementsFrame(); } @@ -2651,7 +2661,7 @@ class AchievementRuntimeExports : private AchievementRuntime return rc_client_can_pause(pClient.GetClient(), frames_remaining); } - static void reset() + static void reset() noexcept { #ifndef RA_UTEST _RA_OnReset(); @@ -2705,13 +2715,13 @@ class AchievementRuntimeExports : private AchievementRuntime s_callbacks.log_callback(sMessage, s_callbacks.log_client); } - static void EventHandlerExternal(const rc_client_event_t* event, rc_client_t*) + static void EventHandlerExternal(const rc_client_event_t* event, rc_client_t*) noexcept(false) { if (s_callbacks.event_handler) s_callbacks.event_handler(event, s_callbacks.event_client); } - static uint32_t ReadMemoryBlock(uint32_t address, uint8_t* buffer, uint32_t num_bytes) + static uint32_t ReadMemoryBlock(uint32_t address, uint8_t* buffer, uint32_t num_bytes) noexcept(false) { if (s_callbacks.read_memory_handler) return s_callbacks.read_memory_handler(address, buffer, num_bytes, s_callbacks.read_memory_client); @@ -2719,7 +2729,7 @@ class AchievementRuntimeExports : private AchievementRuntime return 0; } - static uint32_t ReadMemoryExternal(uint32_t address, uint8_t* buffer, uint32_t num_bytes, rc_client_t*) + static uint32_t ReadMemoryExternal(uint32_t address, uint8_t* buffer, uint32_t num_bytes, rc_client_t*) noexcept(false) { if (s_callbacks.read_memory_handler) return s_callbacks.read_memory_handler(address, buffer, num_bytes, s_callbacks.read_memory_client); @@ -2727,7 +2737,7 @@ class AchievementRuntimeExports : private AchievementRuntime return 0; } - static rc_clock_t GetTimeMillisecsExternal(const rc_client_t*) + static rc_clock_t GetTimeMillisecsExternal(const rc_client_t*) noexcept(false) { if (s_callbacks.get_time_millisecs_handler) return s_callbacks.get_time_millisecs_handler(s_callbacks.get_time_millisecs_client); @@ -2735,19 +2745,19 @@ class AchievementRuntimeExports : private AchievementRuntime return 0; } - static void destroy_achievement_list(rc_client_achievement_list_info_t* list) + static void destroy_achievement_list(rc_client_achievement_list_info_t* list) noexcept { if (list) free(list); } - static void destroy_leaderboard_list(rc_client_leaderboard_list_info_t* list) + static void destroy_leaderboard_list(rc_client_leaderboard_list_info_t* list) noexcept { if (list) free(list); } - static void destroy_leaderboard_entry_list(rc_client_leaderboard_entry_list_info_t* list) + static void destroy_leaderboard_entry_list(rc_client_leaderboard_entry_list_info_t* list) noexcept { if (list) free(list); diff --git a/src/services/impl/WindowsHttpRequester.cpp b/src/services/impl/WindowsHttpRequester.cpp index ba2544ed..25950d71 100644 --- a/src/services/impl/WindowsHttpRequester.cpp +++ b/src/services/impl/WindowsHttpRequester.cpp @@ -157,6 +157,7 @@ unsigned int WindowsHttpRequester::Request(const Http::Request& pRequest, TextWr // open the connection auto sPathWide = ra::Widen(sPath); + GSL_SUPPRESS_ES47 HINTERNET hRequest = WinHttpOpenRequest(hConnect, sPostData.empty() ? L"GET" : L"POST", sPathWide.c_str(), @@ -185,6 +186,7 @@ unsigned int WindowsHttpRequester::Request(const Http::Request& pRequest, TextWr // send the request if (sPostData.empty()) { + GSL_SUPPRESS_ES47 bResults = WinHttpSendRequest(hRequest, sHeaders.c_str(), gsl::narrow_cast(sHeaders.length()), WINHTTP_NO_REQUEST_DATA, @@ -195,7 +197,7 @@ unsigned int WindowsHttpRequester::Request(const Http::Request& pRequest, TextWr { bResults = WinHttpSendRequest(hRequest, sHeaders.c_str(), gsl::narrow_cast(sHeaders.length()), - static_cast(sPostData.data()), + sPostData.data(), gsl::narrow_cast(sPostData.length()), gsl::narrow_cast(sPostData.length()), 0); } @@ -319,7 +321,7 @@ std::string WindowsHttpRequester::GetStatusCodeText(unsigned int nStatusCode) co const DWORD nResult = ::FormatMessage(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, ::GetModuleHandle(TEXT("winhttp.dll")), nStatusCode, 0, (LPTSTR)szMessageBuffer, - sizeof(szMessageBuffer)/sizeof(szMessageBuffer[0]), NULL); + sizeof(szMessageBuffer)/sizeof(szMessageBuffer[0]), nullptr); if (nResult > 0) { diff --git a/src/ui/drawing/gdi/GDISurface.cpp b/src/ui/drawing/gdi/GDISurface.cpp index 3c45cab1..f0285bb6 100644 --- a/src/ui/drawing/gdi/GDISurface.cpp +++ b/src/ui/drawing/gdi/GDISurface.cpp @@ -125,7 +125,7 @@ void GDISurface::DrawSurface(int nX, int nY, const ISurface& pSurface) if (pGDISurface != nullptr) { ::BitBlt(m_hDC, nX, nY, - static_cast(pSurface.GetWidth()), static_cast(pSurface.GetHeight()), + gsl::narrow_cast(pSurface.GetWidth()), gsl::narrow_cast(pSurface.GetHeight()), pGDISurface->m_hDC, 0, 0, SRCCOPY); } } diff --git a/src/ui/drawing/gdi/ImageRepository.cpp b/src/ui/drawing/gdi/ImageRepository.cpp index 7b4f7f10..5051e414 100644 --- a/src/ui/drawing/gdi/ImageRepository.cpp +++ b/src/ui/drawing/gdi/ImageRepository.cpp @@ -39,6 +39,7 @@ bool ImageRepository::Initialize() if (SUCCEEDED(hr) || hr == RPC_E_CHANGED_MODE) { + GSL_SUPPRESS_TYPE1 hr = CoCreateInstance( #if defined (__cplusplus)