From 35befd82bb0ec19f2bbe71c00a2fe17b7c49ca09 Mon Sep 17 00:00:00 2001 From: Skyaero <21192585+Skyaero42@users.noreply.github.com> Date: Fri, 14 Nov 2025 14:08:21 +0100 Subject: [PATCH 1/4] tweak(debug): Add error handling for rename failures in Debug.cpp Previously, the code assumed that the `rename` function would always succeed. This commit introduces error handling. If `rename` fails, the code now logs an error message and removes the file that could not be renamed. This removes 3 compiler warnings. --- .../GameEngine/Source/Common/System/Debug.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Core/GameEngine/Source/Common/System/Debug.cpp b/Core/GameEngine/Source/Common/System/Debug.cpp index e114aea4967..9287317e3d8 100644 --- a/Core/GameEngine/Source/Common/System/Debug.cpp +++ b/Core/GameEngine/Source/Common/System/Debug.cpp @@ -404,7 +404,12 @@ void DebugInit(int flags) strlcat(theLogFileName, ".txt", ARRAY_SIZE(theLogFileNamePrev)); remove(theLogFileNamePrev); - rename(theLogFileName, theLogFileNamePrev); + if (rename(theLogFileName, theLogFileNamePrev) != 0) + { + DEBUG_ASSERTLOG(false, ("Could not rename log file and will remove instead")); + remove(theLogFileName); + } + theLogFile = fopen(theLogFileName, "w"); if (theLogFile != NULL) { @@ -738,7 +743,11 @@ void ReleaseCrash(const char *reason) strlcat(curbuf, RELEASECRASH_FILE_NAME, ARRAY_SIZE(curbuf)); remove(prevbuf); - rename(curbuf, prevbuf); + if (rename(curbuf, prevbuf) != 0) + { + DEBUG_ASSERTLOG(false, ("Could not rename buffer file and will remove instead")); + remove(curbuf); + } theReleaseCrashLogFile = fopen(curbuf, "w"); if (theReleaseCrashLogFile) @@ -827,7 +836,11 @@ void ReleaseCrashLocalized(const AsciiString& p, const AsciiString& m) strlcat(curbuf, RELEASECRASH_FILE_NAME, ARRAY_SIZE(curbuf)); remove(prevbuf); - rename(curbuf, prevbuf); + if (rename(curbuf, prevbuf) != 0) + { + DEBUG_ASSERTLOG(false, ("Could not rename buffer file and will remove instead")); + remove(curbuf); + } theReleaseCrashLogFile = fopen(curbuf, "w"); if (theReleaseCrashLogFile) From dd7b58dc916088cde5d6152388b7cf9c723f1620 Mon Sep 17 00:00:00 2001 From: Skyaero <21192585+Skyaero42@users.noreply.github.com> Date: Fri, 14 Nov 2025 20:17:25 +0100 Subject: [PATCH 2/4] chore: Use DebugLog instead of Debug_assert and change log message --- Core/GameEngine/Source/Common/System/Debug.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/GameEngine/Source/Common/System/Debug.cpp b/Core/GameEngine/Source/Common/System/Debug.cpp index 9287317e3d8..6660a06986e 100644 --- a/Core/GameEngine/Source/Common/System/Debug.cpp +++ b/Core/GameEngine/Source/Common/System/Debug.cpp @@ -406,7 +406,7 @@ void DebugInit(int flags) remove(theLogFileNamePrev); if (rename(theLogFileName, theLogFileNamePrev) != 0) { - DEBUG_ASSERTLOG(false, ("Could not rename log file and will remove instead")); + DebugLog("Could not rename log file '%s' to '%s' and is remove instead", theLogFileName, theLogFileNamePrev); remove(theLogFileName); } @@ -745,7 +745,7 @@ void ReleaseCrash(const char *reason) remove(prevbuf); if (rename(curbuf, prevbuf) != 0) { - DEBUG_ASSERTLOG(false, ("Could not rename buffer file and will remove instead")); + DebugLog("Could not rename buffer file '%s' to '%s' and is remove instead", curbuf, prevbuf); remove(curbuf); } @@ -838,7 +838,7 @@ void ReleaseCrashLocalized(const AsciiString& p, const AsciiString& m) remove(prevbuf); if (rename(curbuf, prevbuf) != 0) { - DEBUG_ASSERTLOG(false, ("Could not rename buffer file and will remove instead")); + DebugLog("Could not rename buffer file '%s' to '%s' and is remove instead", curbuf, prevbuf); remove(curbuf); } From 278009f7abdcb3a4924f01a2a47459ef9b61ba65 Mon Sep 17 00:00:00 2001 From: Skyaero <21192585+Skyaero42@users.noreply.github.com> Date: Sat, 15 Nov 2025 21:59:41 +0100 Subject: [PATCH 3/4] Updating --- .../GameEngine/Source/Common/System/Debug.cpp | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/Core/GameEngine/Source/Common/System/Debug.cpp b/Core/GameEngine/Source/Common/System/Debug.cpp index 6660a06986e..4b00bbdb8b6 100644 --- a/Core/GameEngine/Source/Common/System/Debug.cpp +++ b/Core/GameEngine/Source/Common/System/Debug.cpp @@ -406,8 +406,15 @@ void DebugInit(int flags) remove(theLogFileNamePrev); if (rename(theLogFileName, theLogFileNamePrev) != 0) { - DebugLog("Could not rename log file '%s' to '%s' and is remove instead", theLogFileName, theLogFileNamePrev); - remove(theLogFileName); +#ifdef DEBUG_LOGGING + DebugLog("Warning: Could not rename buffer file '%s' to '%s' and is remove instead", theLogFileName, theLogFileNamePrev); +#endif + if (remove(theLogFileName) != 0) + { +#ifdef DEBUG_LOGGING + DebugLog("Warning: Failed to remove file '%s'.", theLogFileName); +#endif + } } theLogFile = fopen(theLogFileName, "w"); @@ -745,8 +752,15 @@ void ReleaseCrash(const char *reason) remove(prevbuf); if (rename(curbuf, prevbuf) != 0) { - DebugLog("Could not rename buffer file '%s' to '%s' and is remove instead", curbuf, prevbuf); - remove(curbuf); +#ifdef DEBUG_LOGGING + DebugLog("Warning: Could not rename buffer file '%s' to '%s' and is remove instead", curbuf, prevbuf); +#endif + if (remove(curbuf) != 0) + { +#ifdef DEBUG_LOGGING + DebugLog("Warning: Failed to remove file '%s'.", curbuf); +#endif + } } theReleaseCrashLogFile = fopen(curbuf, "w"); @@ -838,8 +852,15 @@ void ReleaseCrashLocalized(const AsciiString& p, const AsciiString& m) remove(prevbuf); if (rename(curbuf, prevbuf) != 0) { - DebugLog("Could not rename buffer file '%s' to '%s' and is remove instead", curbuf, prevbuf); - remove(curbuf); +#ifdef DEBUG_LOGGING + DebugLog("Warning: Could not rename buffer file '%s' to '%s' and is remove instead", curbuf, prevbuf); +#endif + if (remove(curbuf) != 0) + { +#ifdef DEBUG_LOGGING + DebugLog("Warning: Failed to remove file '%s'.", curbuf); +#endif + } } theReleaseCrashLogFile = fopen(curbuf, "w"); From 9b670f6ed4921883e7f9defe23de80bf8645ecd6 Mon Sep 17 00:00:00 2001 From: Skyaero <21192585+Skyaero42@users.noreply.github.com> Date: Sun, 16 Nov 2025 15:01:23 +0100 Subject: [PATCH 4/4] sorry I'm a dummy --- Core/GameEngine/Source/Common/System/Debug.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Core/GameEngine/Source/Common/System/Debug.cpp b/Core/GameEngine/Source/Common/System/Debug.cpp index 4b00bbdb8b6..385dd856161 100644 --- a/Core/GameEngine/Source/Common/System/Debug.cpp +++ b/Core/GameEngine/Source/Common/System/Debug.cpp @@ -407,12 +407,12 @@ void DebugInit(int flags) if (rename(theLogFileName, theLogFileNamePrev) != 0) { #ifdef DEBUG_LOGGING - DebugLog("Warning: Could not rename buffer file '%s' to '%s' and is remove instead", theLogFileName, theLogFileNamePrev); + DebugLog("Warning: Could not rename buffer file '%s' to '%s'. Will remove instead", theLogFileName, theLogFileNamePrev); #endif if (remove(theLogFileName) != 0) { #ifdef DEBUG_LOGGING - DebugLog("Warning: Failed to remove file '%s'.", theLogFileName); + DebugLog("Warning: Failed to remove file '%s'", theLogFileName); #endif } } @@ -753,12 +753,12 @@ void ReleaseCrash(const char *reason) if (rename(curbuf, prevbuf) != 0) { #ifdef DEBUG_LOGGING - DebugLog("Warning: Could not rename buffer file '%s' to '%s' and is remove instead", curbuf, prevbuf); + DebugLog("Warning: Could not rename buffer file '%s' to '%s'. Will remove instead", curbuf, prevbuf); #endif if (remove(curbuf) != 0) { #ifdef DEBUG_LOGGING - DebugLog("Warning: Failed to remove file '%s'.", curbuf); + DebugLog("Warning: Failed to remove file '%s'", curbuf); #endif } } @@ -853,12 +853,12 @@ void ReleaseCrashLocalized(const AsciiString& p, const AsciiString& m) if (rename(curbuf, prevbuf) != 0) { #ifdef DEBUG_LOGGING - DebugLog("Warning: Could not rename buffer file '%s' to '%s' and is remove instead", curbuf, prevbuf); + DebugLog("Warning: Could not rename buffer file '%s' to '%s'. Will remove instead", curbuf, prevbuf); #endif if (remove(curbuf) != 0) { #ifdef DEBUG_LOGGING - DebugLog("Warning: Failed to remove file '%s'.", curbuf); + DebugLog("Warning: Failed to remove file '%s'", curbuf); #endif } }