]> git.sesse.net Git - stockfish/commitdiff
Avoid crashing on Log File opening
authorJoost VandeVondele <Joost.VandeVondele@gmail.com>
Mon, 21 Oct 2019 06:05:14 +0000 (08:05 +0200)
committerStéphane Nicolet <cassio@free.fr>
Mon, 21 Oct 2019 22:02:46 +0000 (00:02 +0200)
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: https://github.com/official-stockfish/Stockfish/issues/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 https://github.com/official-stockfish/Stockfish/pull/2366

No functional change.

src/misc.cpp

index 17644eed89545d88071b18e6795bb895f7df35dc..6f908fd2730bb61cc3645449886616ac0e9a5e54 100644 (file)
@@ -102,6 +102,13 @@ public:
     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);
     }