From: Marco Costalba Date: Thu, 7 Oct 2010 02:55:08 +0000 (+0100) Subject: Properly set to zero stuff returned by 'new' X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=9ca4359f3691305fc5e3306c3084c83557ce09c0;p=fairystockfish.git Properly set to zero stuff returned by 'new' 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 --- diff --git a/src/material.cpp b/src/material.cpp index 71e057a..5e8f75d 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -146,6 +146,7 @@ MaterialInfoTable::MaterialInfoTable() { << " bytes for material hash table." << endl; Application::exit_with_failure(); } + memset(entries, 0, MaterialTableSize * sizeof(MaterialInfo)); } MaterialInfoTable::~MaterialInfoTable() { diff --git a/src/pawns.cpp b/src/pawns.cpp index 07decab..9a0059d 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -90,6 +90,7 @@ PawnInfoTable::PawnInfoTable() { << " bytes for pawn hash table." << std::endl; Application::exit_with_failure(); } + memset(entries, 0, PawnTableSize * sizeof(PawnInfo)); } diff --git a/src/tt.cpp b/src/tt.cpp index b730dbe..375c00a 100644 --- a/src/tt.cpp +++ b/src/tt.cpp @@ -72,6 +72,7 @@ void TranspositionTable::set_size(size_t mbSize) { << " MB for transposition table." << std::endl; Application::exit_with_failure(); } + clear(); } }