From: Marco Costalba Date: Sat, 1 Jan 2011 14:07:45 +0000 (+0100) Subject: Fix an off-by-one bug in sort_multipv() X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=3201a434603b0cd6707391c9026f31a519d46dc0 Fix an off-by-one bug in sort_multipv() Second parameter of insertion_sort() is a pointer to the element _after_ the last of the list, e.g. end() when sorting all items. If we want to sort say the first 2 moves we should write: sort_multipv(2); So, becuase in root moves loop move counter 'i' starts from 0, we need to pass: sort_multipv(i+1); To sort up to move 'i' included. Signed-off-by: Marco Costalba --- diff --git a/src/search.cpp b/src/search.cpp index 1b6cf365..355eed1b 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -149,7 +149,7 @@ namespace { void set_non_pv_scores(const Position& pos); void sort() { insertion_sort(begin(), end()); } - void sort_multipv(int n) { insertion_sort(begin(), begin() + n); } + void sort_multipv(int n) { insertion_sort(begin(), begin() + n + 1); } };