Skip to content

Commit

Permalink
Avoid crashing on Log File opening
Browse files Browse the repository at this point in the history
Stockfish crashes immediately if users enter a wrong file name (or even an existing
folder name) for debug log file. It may be hard for users to find out since it prints
nothing. If they enter the string via a chess GUI, the chess GUI may remember and
auto-send to Stockfish next time, makes Stockfish crashes all the time. Bug report by
Nguyen Hong Pham in this issue: #2365

This patch avoids the crash and instead prefers to exit gracefully with a error
message on std:cerr, like we do with the fenFile for instance.

Closes #2366

No functional change.
  • Loading branch information
vondele authored and snicolet committed Oct 21, 2019
1 parent 12d58ad commit 215cd19
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ class Logger {
if (!fname.empty() && !l.file.is_open())
{
l.file.open(fname, ifstream::out);

if (!l.file.is_open())
{
cerr << "Unable to open debug log file " << fname << endl;
exit(EXIT_FAILURE);
}

cin.rdbuf(&l.in);
cout.rdbuf(&l.out);
}
Expand Down

0 comments on commit 215cd19

Please sign in to comment.