Sfoglia il codice sorgente

Prevent out of bounds array access.

Karlis Senko 7 anni fa
parent
commit
7fb7ceaad7
1 ha cambiato i file con 17 aggiunte e 21 eliminazioni
  1. 17 21
      client/battle/CBattleAnimations.cpp

+ 17 - 21
client/battle/CBattleAnimations.cpp

@@ -1129,7 +1129,6 @@ bool CEffectAnimation::init()
 	else // Effects targeted at a specific creature/hex.
 	{
 		const CStack * destStack = owner->getCurrentPlayerInterface()->cb->battleGetStackByPos(destTile, false);
-		Rect & tilePos = owner->bfield[destTile]->pos;
 		BattleEffect be;
 		be.effectID = ID;
 		be.animation = animation;
@@ -1141,30 +1140,27 @@ bool CEffectAnimation::init()
 //			if(effect == 1)
 //				be.maxFrame = 3;
 
-		if(x == -1)
+		be.x = x;
+		be.y = y;
+		if(destTile.isValid())
 		{
-			be.x = tilePos.x + tilePos.w/2 - first->width()/2;
-		}
-		else
-		{
-			be.x = x;
-		}
+			Rect & tilePos = owner->bfield[destTile]->pos;
+			if(x == -1)
+				be.x = tilePos.x + tilePos.w/2 - first->width()/2;
+			if(y == -1)
+			{
+				if(alignToBottom)
+					be.y = tilePos.y + tilePos.h - first->height();
+				else
+					be.y = tilePos.y - first->height()/2;
+			}
 
-		if(y == -1)
-		{
-			if(alignToBottom)
-				be.y = tilePos.y + tilePos.h - first->height();
-			else
-				be.y = tilePos.y - first->height()/2;
-		}
-		else
-		{
-			be.y = y;
+			// Correction for 2-hex creatures.
+			if(destStack != nullptr && destStack->doubleWide())
+				be.x += (destStack->side == BattleSide::ATTACKER ? -1 : 1)*tilePos.w/2;
 		}
 
-		// Correction for 2-hex creatures.
-		if(destStack != nullptr && destStack->doubleWide())
-			be.x += (destStack->side == BattleSide::ATTACKER ? -1 : 1)*tilePos.w/2;
+		assert(be.x != -1 && be.y != -1);
 
 		//Indicate if effect should be drawn on top of everything or just on top of the hex
 		be.position = destTile;