]> git.sesse.net Git - stockfish/blobdiff - src/evaluate.cpp
Fix overflow in init_safety
[stockfish] / src / evaluate.cpp
index 3680dd36fc30131867bfac8f588bd0ce30731636..9bb6c1c00516446bde294b38da18443c39da25d3 100644 (file)
@@ -870,7 +870,7 @@ namespace {
   }
 
 
-  // evaluate_passed_pawns() evaluates the passed pawns of the given color
+  // evaluate_passed_pawns_of_color() evaluates the passed pawns of the given color
 
   template<Color Us>
   void evaluate_passed_pawns_of_color(const Position& pos, int movesToGo[], Square pawnToGo[], EvalInfo& ei) {
@@ -961,7 +961,7 @@ namespace {
             qsq = relative_square(Us, make_square(square_file(s), RANK_8));
             d =  square_distance(s, qsq)
                - square_distance(theirKingSq, qsq)
-               + (Us != pos.side_to_move());
+               + int(Us != pos.side_to_move());
 
             if (d < 0)
             {
@@ -1217,11 +1217,10 @@ namespace {
             SafetyTable[i] = Value((int)(a * (i - b) * (i - b)));
     }
 
-    for (int i = 0; i < 100; i++)
+    for (int i = 1; i < 100; i++)
     {
-        if (SafetyTable[i+1] - SafetyTable[i] > maxSlope)
-            for (int j = i + 1; j < 100; j++)
-                SafetyTable[j] = SafetyTable[j-1] + Value(maxSlope);
+        if (SafetyTable[i] - SafetyTable[i - 1] > maxSlope)
+            SafetyTable[i] = SafetyTable[i - 1] + Value(maxSlope);
 
         if (SafetyTable[i]  > Value(peak))
             SafetyTable[i] = Value(peak);