From 9ca4359f3691305fc5e3306c3084c83557ce09c0 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Thu, 7 Oct 2010 03:55:08 +0100 Subject: [PATCH] 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 --- src/material.cpp | 1 + src/pawns.cpp | 1 + src/tt.cpp | 1 + 3 files changed, 3 insertions(+) diff --git a/src/material.cpp b/src/material.cpp index 71e057a7..5e8f75d9 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 07decab1..9a0059dc 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 b730dbeb..375c00a6 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(); } } -- 2.39.2