]> git.sesse.net Git - stockfish/commitdiff
Properly set to zero stuff returned by 'new'
authorMarco Costalba <mcostalba@gmail.com>
Thu, 7 Oct 2010 02:55:08 +0000 (03:55 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Thu, 7 Oct 2010 02:57:33 +0000 (03:57 +0100)
Language guarantees that c'tor is called, but without any c'tor
it happens to work by accident because OS zeroes out the freshly
allocated pages. The problem is that if I deallocate and allocate
again, the second time pages are no more newly come by the OS and
so could contain stale info.

A practical case could be if we change TT size or numbers of
threads on the fly while already running.

Bug spotted by Justin Blanchard.

No functional change.

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

index 71e057a7116d10d7bdb36602eb4f507de0dcd13a..5e8f75d9cc4b6c2561fdd5b1a5bb784078be323c 100644 (file)
@@ -146,6 +146,7 @@ MaterialInfoTable::MaterialInfoTable() {
            << " bytes for material hash table." << endl;
       Application::exit_with_failure();
   }
            << " bytes for material hash table." << endl;
       Application::exit_with_failure();
   }
+  memset(entries, 0, MaterialTableSize * sizeof(MaterialInfo));
 }
 
 MaterialInfoTable::~MaterialInfoTable() {
 }
 
 MaterialInfoTable::~MaterialInfoTable() {
index 07decab1fd4c52e9c490f5468c5f4c94d9d73b31..9a0059dcec379e7e64a3e20ad43525601aaa8f4d 100644 (file)
@@ -90,6 +90,7 @@ PawnInfoTable::PawnInfoTable() {
                 << " bytes for pawn hash table." << std::endl;
       Application::exit_with_failure();
   }
                 << " bytes for pawn hash table." << std::endl;
       Application::exit_with_failure();
   }
+  memset(entries, 0, PawnTableSize * sizeof(PawnInfo));
 }
 
 
 }
 
 
index b730dbeb63bafd6adc78424f8aba0ceb3983a22d..375c00a67308fbc934e7cad2fe569f5a780468f3 100644 (file)
@@ -72,6 +72,7 @@ void TranspositionTable::set_size(size_t mbSize) {
                     << " MB for transposition table." << std::endl;
           Application::exit_with_failure();
       }
                     << " MB for transposition table." << std::endl;
           Application::exit_with_failure();
       }
+      clear();
   }
 }
 
   }
 }