Real fix to ammo slot overflow (bug triggered by r2411 fix)
authorunc0rr
Mon, 12 Oct 2009 16:53:01 +0000 (2009-10-12)
changeset 2431 23242609c44b
parent 2430 b87046cd8ae4
child 2432 1a0bb82d55f0
Real fix to ammo slot overflow (bug triggered by r2411 fix)
hedgewars/uAmmos.pas
hedgewars/uTeams.pas
--- a/hedgewars/uAmmos.pas	Mon Oct 12 16:50:42 2009 +0000
+++ b/hedgewars/uAmmos.pas	Mon Oct 12 16:53:01 2009 +0000
@@ -221,10 +221,10 @@
 		begin
 		CurAmmo:= 0;
 		CurSlot:= 0;
-		while (CurSlot < cMaxSlotIndex) and (Ammo^[CurSlot, CurAmmo].Count = 0) do 
-                        inc(CurSlot)
+		while (CurSlot <= cMaxSlotIndex) and (Ammo^[CurSlot, CurAmmo].Count = 0) do inc(CurSlot);
+		TryDo(CurSlot <= cMaxSlotIndex, 'Ammo slot index overflow', true)
 		end;
-                
+
         //bad things could happen here in case CurSlot is overflowing
 	ApplyAngleBounds(Hedgehog, Ammo^[CurSlot, CurAmmo].AmmoType);
 
@@ -255,15 +255,17 @@
 procedure SwitchNotHeldAmmo(var Hedgehog: THedgehog);
 begin
 with Hedgehog do
-     if ((Ammo^[CurSlot, CurAmmo].Propz and ammoprop_DontHold) <> 0) or
-        (Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0) then
-        begin
-        CurAmmo:= 0;
-        CurSlot:= 0;
-        while (CurSlot < cMaxSlotIndex) and
-              ((Ammo^[CurSlot, CurAmmo].Count = 0) or
-              (Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0))
-              do inc(CurSlot)
+	if ((Ammo^[CurSlot, CurAmmo].Propz and ammoprop_DontHold) <> 0) or
+		(Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0) then
+		begin
+		CurAmmo:= 0;
+		CurSlot:= 0;
+		while (CurSlot <= cMaxSlotIndex) and
+			((Ammo^[CurSlot, CurAmmo].Count = 0) or
+			(Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0))
+			do
+			inc(CurSlot);
+		TryDo(CurSlot <= cMaxSlotIndex, 'Ammo slot index overflow', true)
         end
 end;
 
--- a/hedgewars/uTeams.pas	Mon Oct 12 16:50:42 2009 +0000
+++ b/hedgewars/uTeams.pas	Mon Oct 12 16:53:01 2009 +0000
@@ -208,7 +208,10 @@
 procedure AfterSwitchHedgehog;
 var g: PGear;
 begin
+inc(CurrentTeam^.Clan^.TurnNumber);
+
 SwitchNotHeldAmmo(CurrentHedgehog^);
+
 with CurrentHedgehog^ do
 	begin
 	with Gear^ do
@@ -222,8 +225,6 @@
 	FollowGear:= Gear
 	end;
 
-inc(CurrentTeam^.Clan^.TurnNumber);
-
 ResetKbd;
 
 cWindSpeed:= rndSign(GetRandom * cMaxWindSpeed);