From becf8eb6a5c2bf9be01f0ea5d4d756d24116d098 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 3 Jul 2022 19:18:23 +0200 Subject: [PATCH] Use size_t for SDK_ARRAYSIZE instead sizeof() returns a size_t. --- r5dev/core/dllmain.cpp | 4 ++-- r5dev/tier0/basetypes.h | 2 +- r5dev/tier1/IConVar.cpp | 12 ++++-------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/r5dev/core/dllmain.cpp b/r5dev/core/dllmain.cpp index 5f8d1cd2..1072cee0 100644 --- a/r5dev/core/dllmain.cpp +++ b/r5dev/core/dllmain.cpp @@ -35,10 +35,10 @@ void R5Dev_Init() #endif // !DEDICATED SpdLog_Init(); spdlog::info("\n"); - for (int i = 0; i < (&R5R_EMBLEM)[1] - R5R_EMBLEM; i++) + for (size_t i = 0; i < SDK_ARRAYSIZE(R5R_EMBLEM); i++) { std::string svEscaped = StringEscape(R5R_EMBLEM[i]); - spdlog::info("{}{}{}\n", g_svRedF.c_str(), svEscaped.c_str(), g_svReset.c_str()); + spdlog::info("{:s}{:s}{:s}\n", g_svRedF.c_str(), svEscaped.c_str(), g_svReset.c_str()); } spdlog::info("\n"); diff --git a/r5dev/tier0/basetypes.h b/r5dev/tier0/basetypes.h index c2819055..799574ba 100644 --- a/r5dev/tier0/basetypes.h +++ b/r5dev/tier0/basetypes.h @@ -135,7 +135,7 @@ #define MAX_MAP_NAME 64 #define SDK_VERSION "VGameSDK001" // Increment this with every /breaking/ SDK change (i.e. security/backend changes breaking compatibility). -#define SDK_ARRAYSIZE(arr) ((int)(sizeof(arr) / sizeof(*arr))) // Name due to IMGUI implementation and NT implementation that we shouldn't share across everywhere. +#define SDK_ARRAYSIZE(arr) ((sizeof(arr) / sizeof(*arr))) // Name due to IMGUI implementation and NT implementation that we shouldn't share across everywhere. #ifndef DEDICATED #define SDK_DEFAULT_CFG "platform\\cfg\\startup_default.cfg" diff --git a/r5dev/tier1/IConVar.cpp b/r5dev/tier1/IConVar.cpp index de311846..581b12d9 100644 --- a/r5dev/tier1/IConVar.cpp +++ b/r5dev/tier1/IConVar.cpp @@ -204,11 +204,9 @@ void ConVar::PurgeShipped(void) const "voice_enabled", }; - for (int i = 0; i < SDK_ARRAYSIZE(pszToPurge); i++) + for (size_t i = 0; i < SDK_ARRAYSIZE(pszToPurge); i++) { - ConVar* pCVar = g_pCVar->FindVar(pszToPurge[i]); - - if (pCVar) + if (ConVar* pCVar = g_pCVar->FindVar(pszToPurge[i])) { pCVar->SetValue(0); } @@ -241,11 +239,9 @@ void ConVar::PurgeHostNames(void) const "users_hostname" }; - for (int i = 0; i < SDK_ARRAYSIZE(pszHostNames); i++) + for (size_t i = 0; i < SDK_ARRAYSIZE(pszHostNames); i++) { - ConVar* pCVar = g_pCVar->FindVar(pszHostNames[i]); - - if (pCVar) + if (ConVar* pCVar = g_pCVar->FindVar(pszHostNames[i])) { pCVar->ChangeStringValueUnsafe("0.0.0.0"); }