Skip to content

Commit

Permalink
Redirect stdout to NUL if the log file can't be opened
Browse files Browse the repository at this point in the history
  • Loading branch information
cgutman committed Apr 17, 2022
1 parent 771e34f commit 8f01144
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion GS-IPv6-Forwarder
6 changes: 5 additions & 1 deletion miss/miss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,11 @@ void ResetLogFile(bool standaloneExe)
MoveFileExA(currentLogFilePath, oldLogFilePath, MOVEFILE_REPLACE_EXISTING);

// Redirect stdout to this new file
freopen(currentLogFilePath, "w", stdout);
if (freopen(currentLogFilePath, "w", stdout) == NULL) {
// If we couldn't create a log file, just redirect stdout to NUL.
// We have to open _something_ or printf() will crash.
freopen("NUL", "w", stdout);
}
}

// Print a log header
Expand Down

0 comments on commit 8f01144

Please sign in to comment.