Przeglądaj źródła

Merge pull request #4714 from IvanSavenko/integer_overflow_fix

Fix potential int32_t overflow when computing total army value
Ivan Savenko 1 rok temu
rodzic
commit
b79897f598
2 zmienionych plików z 4 dodań i 2 usunięć
  1. 1 1
      lib/CCreatureSet.cpp
  2. 3 1
      lib/mapObjects/CGCreature.cpp

+ 1 - 1
lib/CCreatureSet.cpp

@@ -855,7 +855,7 @@ std::string CStackInstance::getName() const
 ui64 CStackInstance::getPower() const
 {
 	assert(type);
-	return type->getAIValue() * count;
+	return static_cast<ui64>(type->getAIValue()) * count;
 }
 
 ArtBearer::ArtBearer CStackInstance::bearerType() const

+ 3 - 1
lib/mapObjects/CGCreature.cpp

@@ -110,7 +110,9 @@ std::string CGCreature::getPopupText(const CGHeroInstance * hero) const
 		hoverName += VLC->generaltexth->translate("vcmi.adventureMap.monsterThreat.title");
 
 		int choice;
-		double ratio = (static_cast<double>(getArmyStrength()) / hero->getTotalStrength());
+		uint64_t armyStrength = getArmyStrength();
+		uint64_t heroStrength = hero->getTotalStrength();
+		double ratio = static_cast<double>(armyStrength) / heroStrength;
 		if (ratio < 0.1)  choice = 0;
 		else if (ratio < 0.25) choice = 1;
 		else if (ratio < 0.6)  choice = 2;