Skip to content

Commit

Permalink
Fixed integer overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
MeridianOXC committed Dec 2, 2023
1 parent c557bf0 commit 23e0ccc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/Basescape/ManufactureInfoState.cpp
Expand Up @@ -575,13 +575,17 @@ void ManufactureInfoState::lessUnitClick(Action *action)
{
if (wasInfinite)
{
// when infinite amount is decreased by 1, set the amount to maximum possible considering current funds and store supplies
int productionPossible = INT_MAX;
// when infinite amount is decreased by 1, set the amount to maximum possible (capped at 999) considering current funds and store supplies
int productionPossible = 999;
auto* manufRule = _production->getRules();
if (manufRule->getManufactureCost() > 0)
{
int byFunds = _game->getSavedGame()->getFunds() / manufRule->getManufactureCost();
productionPossible = std::min(productionPossible, byFunds);
int64_t byFunds = _game->getSavedGame()->getFunds() / manufRule->getManufactureCost();
if (byFunds < 1000LL)
{
int byFundsInt = (int)byFunds;
productionPossible = std::min(productionPossible, byFundsInt);
}
}
for (auto& item : manufRule->getRequiredItems())
{
Expand Down
8 changes: 6 additions & 2 deletions src/Basescape/NewManufactureListState.cpp
Expand Up @@ -407,8 +407,12 @@ void NewManufactureListState::fillProductionList(bool refreshCategories)
int productionPossible = 10; // max
if (manuf->getManufactureCost() > 0)
{
int byFunds = _game->getSavedGame()->getFunds() / manuf->getManufactureCost();
productionPossible = std::min(productionPossible, byFunds);
int64_t byFunds = _game->getSavedGame()->getFunds() / manuf->getManufactureCost();
if (byFunds < 10LL)
{
int byFundsInt = (int)byFunds;
productionPossible = std::min(productionPossible, byFundsInt);
}
}
for (auto& iter : manuf->getRequiredItems())
{
Expand Down

0 comments on commit 23e0ccc

Please sign in to comment.