]> git.sesse.net Git - stockfish/commitdiff
Fix a crash due to a broken Book::open()
authorMarco Costalba <mcostalba@gmail.com>
Sat, 4 Dec 2010 20:19:22 +0000 (21:19 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 5 Dec 2010 08:24:18 +0000 (09:24 +0100)
Bug introduced in 9dcc2aad98b9703

We can be asked to open a non-exsistent file,
in this case we should gracefully handle the
case and silently return instead of exiting.

Bug discovered and bisected down by Joona.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/book.cpp

index 95ccd690506251c284dc557905a53d5c1cc6711f..9528e47c8c9e99c383e22838371723f9e1a09e6f 100644 (file)
@@ -365,18 +365,20 @@ void Book::open(const string& fName) {
   fileName = fName;
   ifstream::open(fileName.c_str(), ifstream::in | ifstream::binary);
 
-  if (is_open())
-  {
-      // Get the book size in number of entries
-      seekg(0, ios::end);
-      bookSize = long(tellg()) / EntrySize;
-      seekg(0, ios::beg);
+  // Silently return when asked to open a non-exsistent file
+  if (!is_open())
+      return;
+
+  // Get the book size in number of entries
+  seekg(0, ios::end);
+  bookSize = long(tellg()) / EntrySize;
+  seekg(0, ios::beg);
 
-      if (good())
-          return;
+  if (!good())
+  {
+      cerr << "Failed to open book file " << fileName << endl;
+      exit(EXIT_FAILURE);
   }
-  cerr << "Failed to open book file " << fileName << endl;
-  exit(EXIT_FAILURE);
 }