瀏覽代碼

[static analysis] [WIP] fix few possible bugs
CBattleAnimations.cpp,CBitmapHandler.cpp,CGameHandler.cpp Possible null pointer dereference

alexvins 13 年之前
父節點
當前提交
2b2b02cccc
共有 3 個文件被更改,包括 18 次插入14 次删除
  1. 2 2
      client/BattleInterface/CBattleAnimations.cpp
  2. 11 8
      client/CBitmapHandler.cpp
  3. 5 4
      server/CGameHandler.cpp

+ 2 - 2
client/BattleInterface/CBattleAnimations.cpp

@@ -691,14 +691,14 @@ void CReverseAnimation::endAnim()
 
 void CReverseAnimation::setupSecondPart()
 {
-	owner->creDir[stack->ID] = !owner->creDir[stack->ID];
-
 	if(!stack)
 	{
 		endAnim();
 		return;
 	}
 
+	owner->creDir[stack->ID] = !owner->creDir[stack->ID];
+
 	Point coords = CClickableHex::getXYUnitAnim(hex, owner->creDir[stack->ID], stack, owner);
 	myAnim()->pos.x = coords.x;
 	//creAnims[stackID]->pos.y = coords.second;

+ 11 - 8
client/CBitmapHandler.cpp

@@ -139,15 +139,18 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fna
 		          SDL_RWFromConstMem((void*)readFile.first.get(), readFile.second),
 		          1, // mark it for auto-deleting
 		          &info.getExtension()[0] + 1); //pass extension without dot (+1 character)
-
-		if (!ret)
-			tlog1<<"Failed to open "<<fname<<" via SDL_Image\n";
-
-		if (ret->format->palette)
+		if (ret)
+		{
+			if (ret->format->palette)
+			{
+				//set correct value for alpha\unused channel
+				for (int i=0; i< ret->format->palette->ncolors; i++)
+					ret->format->palette->colors[i].unused = 255;
+			}			
+		}
+		else
 		{
-			//set correct value for alpha\unused channel
-			for (int i=0; i< ret->format->palette->ncolors; i++)
-				ret->format->palette->colors[i].unused = 255;
+			tlog1<<"Failed to open "<<fname<<" via SDL_Image\n";		
 		}
 	}
 	return ret;

+ 5 - 4
server/CGameHandler.cpp

@@ -3348,16 +3348,17 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
 		{
 			StartAction start_action(ba);
 			sendAndApply(&start_action); //start movement and attack
-			int startingPos = stack->position;
-			int distance = moveStack(ba.stackNumber, ba.destinationTile);
-			const CStack *stackAtEnd = gs->curB->battleGetStackByPos(ba.additionalInfo);
 
+			const CStack *stackAtEnd = gs->curB->battleGetStackByPos(ba.additionalInfo);
 			if(!stack || !stackAtEnd)
 			{
 				sendAndApply(&end_action);
 				break;
 			}
-
+			
+			int distance = moveStack(ba.stackNumber, ba.destinationTile);
+			int startingPos = stack->position;
+			
 			tlog5 << stack->nodeName() << " will attack " << stackAtEnd->nodeName() << std::endl;
 
 			if(stack->position != ba.destinationTile //we wasn't able to reach destination tile