Skip to content

Commit 6461ca5

Browse files
authored
fix(debug): Add error handling for rename failures in Debug code (#1855)
1 parent f1138f1 commit 6461ca5

File tree

1 file changed

+37
-3
lines changed
  • Core/GameEngine/Source/Common/System

1 file changed

+37
-3
lines changed

Core/GameEngine/Source/Common/System/Debug.cpp

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,19 @@ void DebugInit(int flags)
404404
strlcat(theLogFileName, ".txt", ARRAY_SIZE(theLogFileNamePrev));
405405

406406
remove(theLogFileNamePrev);
407-
rename(theLogFileName, theLogFileNamePrev);
407+
if (rename(theLogFileName, theLogFileNamePrev) != 0)
408+
{
409+
#ifdef DEBUG_LOGGING
410+
DebugLog("Warning: Could not rename buffer file '%s' to '%s'. Will remove instead", theLogFileName, theLogFileNamePrev);
411+
#endif
412+
if (remove(theLogFileName) != 0)
413+
{
414+
#ifdef DEBUG_LOGGING
415+
DebugLog("Warning: Failed to remove file '%s'", theLogFileName);
416+
#endif
417+
}
418+
}
419+
408420
theLogFile = fopen(theLogFileName, "w");
409421
if (theLogFile != NULL)
410422
{
@@ -738,7 +750,18 @@ void ReleaseCrash(const char *reason)
738750
strlcat(curbuf, RELEASECRASH_FILE_NAME, ARRAY_SIZE(curbuf));
739751

740752
remove(prevbuf);
741-
rename(curbuf, prevbuf);
753+
if (rename(curbuf, prevbuf) != 0)
754+
{
755+
#ifdef DEBUG_LOGGING
756+
DebugLog("Warning: Could not rename buffer file '%s' to '%s'. Will remove instead", curbuf, prevbuf);
757+
#endif
758+
if (remove(curbuf) != 0)
759+
{
760+
#ifdef DEBUG_LOGGING
761+
DebugLog("Warning: Failed to remove file '%s'", curbuf);
762+
#endif
763+
}
764+
}
742765

743766
theReleaseCrashLogFile = fopen(curbuf, "w");
744767
if (theReleaseCrashLogFile)
@@ -827,7 +850,18 @@ void ReleaseCrashLocalized(const AsciiString& p, const AsciiString& m)
827850
strlcat(curbuf, RELEASECRASH_FILE_NAME, ARRAY_SIZE(curbuf));
828851

829852
remove(prevbuf);
830-
rename(curbuf, prevbuf);
853+
if (rename(curbuf, prevbuf) != 0)
854+
{
855+
#ifdef DEBUG_LOGGING
856+
DebugLog("Warning: Could not rename buffer file '%s' to '%s'. Will remove instead", curbuf, prevbuf);
857+
#endif
858+
if (remove(curbuf) != 0)
859+
{
860+
#ifdef DEBUG_LOGGING
861+
DebugLog("Warning: Failed to remove file '%s'", curbuf);
862+
#endif
863+
}
864+
}
831865

832866
theReleaseCrashLogFile = fopen(curbuf, "w");
833867
if (theReleaseCrashLogFile)

0 commit comments

Comments
 (0)