From 61a054b17002a167a09ce09eb9a7d820d792c680 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 26 May 2012 23:14:37 +0100 Subject: [PATCH] Fix a possible 'Division by zero' In case a book entry has 'count' field set to 0 we crash. Spotted by Clang's static analyzer. No functional change. Signed-off-by: Marco Costalba --- src/book.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/book.cpp b/src/book.cpp index 0fff6827..fbb1984c 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -420,7 +420,7 @@ Move Book::probe(const Position& pos, const string& fName, bool pickBest) { // Choose book move according to its score. If a move has a very // high score it has higher probability to be choosen than a move // with lower score. Note that first entry is always chosen. - if ( (RKiss.rand() % sum < e.count) + if ( (sum && RKiss.rand() % sum < e.count) || (pickBest && e.count == best)) move = Move(e.move); } -- 2.39.2