From 56f8a6911467c522221d7e7a2b0c1234b1ab1b09 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:23:34 +0200 Subject: [PATCH] Tier1: fix flag testing bug in ConVar::Create The archive + playerprofile flags check was done on the uninitialized member variable 'm_nFlags', but it should've been performed on the function's input parameter 'flags' as m_nFlags is only initialized past this check in BaseClass::Create (its part of ConCommandBase). This caused statically initialized ConVar's flagged 'FCVAR_ARCHIVE | FCVAR_ARCHIVE_PLAYERPROFILE' to go undetected, and dynamically initialized ones (e.g. through mod settings) to have random memory and intermittently fail this check. The latter is how this bug was found and ultimately fixed in this patch. --- src/tier1/convar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tier1/convar.cpp b/src/tier1/convar.cpp index 8cca8bae..ff43e9d3 100644 --- a/src/tier1/convar.cpp +++ b/src/tier1/convar.cpp @@ -1020,7 +1020,7 @@ void ConVar::Create(const char* pName, const char* pDefaultValue, int flags /*= // Only 1 of the 2 can be set on a ConVar, both means there is a bug in // your code, fix it! const int nFlagsToCheck = (FCVAR_ARCHIVE | FCVAR_ARCHIVE_PLAYERPROFILE); - if ((m_nFlags & nFlagsToCheck) == nFlagsToCheck) + if ((flags & nFlagsToCheck) == nFlagsToCheck) { Error(eDLL_T::COMMON, EXIT_FAILURE, "Convar '%s' is flagged as both FCVAR_ARCHIVE and FCVAR_ARCHIVE_PLAYERPROFILE.\n", pName);