]> git.sesse.net Git - stockfish/commitdiff
Fix an off-by-one bug in extract_pv()
authorMarco Costalba <mcostalba@gmail.com>
Fri, 9 Oct 2009 09:04:55 +0000 (10:04 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Fri, 9 Oct 2009 09:04:55 +0000 (10:04 +0100)
In case we reach ply == PLY_MAX we exit the function
writing

pv[PLY_MAX] = MOVE_NONE;

And because SearchStack is defined as:

struct SearchStack {
  Move pv[PLY_MAX];
  Move currentMove;
  .....

We end up with the unwanted assignment

SearchStack.currentMove = MOVE_NONE;

Fortunatly this is harmless because currentMove is not used where
extarct_pv() is called. But neverthless this is a bug that
needs to be fixed.

Thanks to Uri Blass for spotting out this.

No functional change.

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

index 069bbdd26e1954d9a872e0f5ddbc5e8978bb9d76..91f484a1a344a4d400ef792817f8d2f761df015d 100644 (file)
@@ -48,7 +48,7 @@ const int KILLER_MAX = 2;
 /// current ply.
 
 struct SearchStack {
-  Move pv[PLY_MAX];
+  Move pv[PLY_MAX_PLUS_2];
   Move currentMove;
   Move mateKiller;
   Move threatMove;
index a16d5cac636496888b9f7e506aad67902907b92c..55aad112af3c252d6006265132e8cb657d70d5f6 100644 (file)
@@ -220,7 +220,7 @@ void TranspositionTable::insert_pv(const Position& pos, Move pv[]) {
 /// will often get single-move PVs when the search stops while failing high,
 /// and a single-move PV means that we don't have a ponder move.
 
-void TranspositionTable::extract_pv(const Position& pos, Move pv[], int pvSize) {
+void TranspositionTable::extract_pv(const Position& pos, Move pv[], const int PLY_MAX) {
 
   const TTEntry* tte;
   StateInfo st;
@@ -236,7 +236,7 @@ void TranspositionTable::extract_pv(const Position& pos, Move pv[], int pvSize)
          && tte->move() != MOVE_NONE
          && move_is_legal(p, tte->move())
          && (!p.is_draw() || ply < 2)
-         && ply < pvSize)
+         && ply < PLY_MAX)
   {
       pv[ply] = tte->move();
       p.do_move(pv[ply++], st);
index bff1749841b1ac1312a7a413d9c3619eb6e461c0..5d0df726239cabb66cb13628ac3523e9fb676c9c 100644 (file)
--- a/src/tt.h
+++ b/src/tt.h
@@ -102,7 +102,7 @@ public:
   void prefetch(const Key posKey) const;
   void new_search();
   void insert_pv(const Position& pos, Move pv[]);
-  void extract_pv(const Position& pos, Move pv[], int pvSize);
+  void extract_pv(const Position& pos, Move pv[], const int PLY_MAX);
   int full() const;
 
 private: