shithub: choc

Download patch

ref: 8878f9e71edf05a44d6dc46a4a03e116ea100b7b
parent: fdd2fe6367646927b54dabe719002709861ef450
author: Simon Howard <[email protected]>
date: Fri Oct 3 13:06:10 EDT 2008

Fix crash with P_FindNextHighestFloor.

Subversion-branch: /branches/raven-branch
Subversion-revision: 1327

--- a/src/heretic/p_spec.c
+++ b/src/heretic/p_spec.c
@@ -408,29 +408,35 @@
 {
     int i;
     int h;
-    int min;
+    fixed_t min;
     line_t *check;
     sector_t *other;
     fixed_t height = currentheight;
-    fixed_t heightlist[20];     // 20 adjoining sectors max!
 
+    min = INT_MAX;
+
     for (i = 0, h = 0; i < sec->linecount; i++)
     {
         check = sec->lines[i];
         other = getNextSector(check, sec);
-        if (!other)
-            continue;
-        if (other->floorheight > height)
-            heightlist[h++] = other->floorheight;
+
+        if (other != NULL && other->floorheight > height)
+        {
+            if (min < other->floorheight)
+            {
+                min = other->floorheight;
+            }
+
+            ++h;
+        }
     }
 
-    //
-    // Find lowest height in list
-    //
-    min = heightlist[0];
-    for (i = 1; i < h; i++)
-        if (heightlist[i] < min)
-            min = heightlist[i];
+    // Compatibility note, in case of demo desyncs.
+
+    if (h > 20)
+    {
+        fprintf(stderr, "P_FindNextHighestFloor: exceeded Vanilla limit\n");
+    }
 
     return min;
 }