Skip to content

Commit f87a72b

Browse files
committed
Fix negative array index
If there was only one object and that got deleted the code that keeps track of the highest object index would cause a negativ array index. I added a check to make sure that the index was positive but that still means that Highest_object_index will be negativ after that function returns. I looked at the usages of the value and that value seems to be fine with that code so I think this should be safe.
1 parent 4321fd3 commit f87a72b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

code/object/object.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,11 @@ void obj_free(int objnum)
452452

453453
Assert(Num_objects >= 0);
454454

455-
if (objnum == Highest_object_index)
456-
while (Objects[--Highest_object_index].type == OBJ_NONE);
457-
455+
if (objnum == Highest_object_index) {
456+
while (Highest_object_index >= 0 && Objects[Highest_object_index].type == OBJ_NONE) {
457+
--Highest_object_index;
458+
}
459+
}
458460
}
459461

460462
/**

0 commit comments

Comments
 (0)