Fix overflow in init_safety
authorJoona Kiiski <joona.kiiski@gmail.com>
Wed, 14 Apr 2010 18:14:16 +0000 (21:14 +0300)
committerMarco Costalba <mcostalba@gmail.com>
Wed, 14 Apr 2010 18:19:11 +0000 (19:19 +0100)
Also write the code in more clean way

No functional change

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

index 2f8e63e5125e7a8f8feb67a90ec1acbb27f74e83..9bb6c1c00516446bde294b38da18443c39da25d3 100644 (file)
@@ -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);