Skip to content

Commit 35befd8

Browse files
committed
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.
1 parent 6cfcc7b commit 35befd8

File tree

1 file changed

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

1 file changed

+16
-3
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,12 @@ 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+
DEBUG_ASSERTLOG(false, ("Could not rename log file and will remove instead"));
410+
remove(theLogFileName);
411+
}
412+
408413
theLogFile = fopen(theLogFileName, "w");
409414
if (theLogFile != NULL)
410415
{
@@ -738,7 +743,11 @@ void ReleaseCrash(const char *reason)
738743
strlcat(curbuf, RELEASECRASH_FILE_NAME, ARRAY_SIZE(curbuf));
739744

740745
remove(prevbuf);
741-
rename(curbuf, prevbuf);
746+
if (rename(curbuf, prevbuf) != 0)
747+
{
748+
DEBUG_ASSERTLOG(false, ("Could not rename buffer file and will remove instead"));
749+
remove(curbuf);
750+
}
742751

743752
theReleaseCrashLogFile = fopen(curbuf, "w");
744753
if (theReleaseCrashLogFile)
@@ -827,7 +836,11 @@ void ReleaseCrashLocalized(const AsciiString& p, const AsciiString& m)
827836
strlcat(curbuf, RELEASECRASH_FILE_NAME, ARRAY_SIZE(curbuf));
828837

829838
remove(prevbuf);
830-
rename(curbuf, prevbuf);
839+
if (rename(curbuf, prevbuf) != 0)
840+
{
841+
DEBUG_ASSERTLOG(false, ("Could not rename buffer file and will remove instead"));
842+
remove(curbuf);
843+
}
831844

832845
theReleaseCrashLogFile = fopen(curbuf, "w");
833846
if (theReleaseCrashLogFile)

0 commit comments

Comments
 (0)