Skip to content

Commit

Permalink
Check for non-nullptr struct to compensate for missing check in `STRU…
Browse files Browse the repository at this point in the history
…CTURE::isFactory()`

Signed-off-by: Pavel Solodovnikov <[email protected]>
  • Loading branch information
ManManson committed Jan 16, 2024
1 parent 656a775 commit c25e85c
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ bool removeDroidBase(DROID *psDel)
for (auto psStruct : apsStructLists[psDel->player])
{
// alexl's stab at a right answer.
if (psStruct->isFactory()
if (psStruct && psStruct->isFactory()
&& psStruct->pFunctionality->factory.psCommander == psDel)
{
assignFactoryCommandDroid(psStruct, nullptr);
Expand Down
4 changes: 2 additions & 2 deletions src/hci/manufacture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static const uint8_t commandBrainComponent = 1; // hmm there is only 1 "CommandB

FACTORY *getFactoryOrNullptr(STRUCTURE *factory)
{
ASSERT_OR_RETURN(nullptr, factory->isFactory(), "Invalid factory pointer");
ASSERT_OR_RETURN(nullptr, factory && factory->isFactory(), "Invalid factory pointer");
return (FACTORY *)factory->pFunctionality;
}

Expand Down Expand Up @@ -197,7 +197,7 @@ void ManufactureController::setHighlightedObject(BASE_OBJECT *object)
}

auto factory = castStructure(object);
ASSERT_OR_RETURN(, factory->isFactory(), "Invalid factory pointer");
ASSERT_OR_RETURN(, factory && factory->isFactory(), "Invalid factory pointer");
highlightedFactory = factory;
}

Expand Down
2 changes: 1 addition & 1 deletion src/intorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ static std::vector<AVORDER> buildDroidOrderList()
// Build a list of orders available for the selected structure.
static std::vector<AVORDER> buildStructureOrderList(STRUCTURE *psStructure)
{
ASSERT_OR_RETURN(std::vector<AVORDER>(), psStructure->isFactory(), "BuildStructureOrderList: structure is not a factory");
ASSERT_OR_RETURN(std::vector<AVORDER>(), psStructure && psStructure->isFactory(), "BuildStructureOrderList: structure is not a factory");

//this can be hard-coded!
std::vector<AVORDER> orders(4);
Expand Down
4 changes: 4 additions & 0 deletions src/mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,10 @@ void saveMissionLimboData()
// any selectedPlayer's factories/research need to be put on holdProduction/holdresearch
for (STRUCTURE* psStruct : apsStructLists[selectedPlayer])
{
if (!psStruct)
{
continue;
}
if (psStruct->isFactory())
{
holdProduction(psStruct, ModeImmediate);
Expand Down
2 changes: 1 addition & 1 deletion src/multijoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ bool splitResourcesAmongTeam(UDWORD player)

mutating_list_iterate(apsStructLists[player], [&cmp, &structsGiftedPerTarget, &incrRecvStruct](STRUCTURE* psStruct)
{
if (cmp(psStruct))
if (psStruct && cmp(psStruct))
{
giftSingleStructure(psStruct, structsGiftedPerTarget.front().player, false);
incrRecvStruct(0);
Expand Down
2 changes: 1 addition & 1 deletion src/multiplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ bool multiplayerWinSequence(bool firstCall)
// stop all manufacture.
for (STRUCTURE* psStruct : apsStructLists[selectedPlayer])
{
if (psStruct->isFactory())
if (psStruct && psStruct->isFactory())
{
if (((FACTORY *)psStruct->pFunctionality)->psSubject)//check if active
{
Expand Down
4 changes: 2 additions & 2 deletions src/order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4028,7 +4028,7 @@ void secondarySetAverageGroupState(UDWORD player, UDWORD group)
*/
bool setFactoryState(STRUCTURE *psStruct, SECONDARY_ORDER sec, SECONDARY_STATE State)
{
if (!psStruct->isFactory())
if (!psStruct || !psStruct->isFactory())
{
ASSERT(false, "setFactoryState: structure is not a factory");
return false;
Expand Down Expand Up @@ -4097,7 +4097,7 @@ bool setFactoryState(STRUCTURE *psStruct, SECONDARY_ORDER sec, SECONDARY_STATE S
*/
bool getFactoryState(const STRUCTURE *psStruct, SECONDARY_ORDER sec, SECONDARY_STATE *pState)
{
ASSERT_OR_RETURN(false, psStruct->isFactory(), "Structure is not a factory");
ASSERT_OR_RETURN(false, psStruct && psStruct->isFactory(), "Structure is not a factory");
if ((FACTORY *)psStruct->pFunctionality)
{
UDWORD state = ((FACTORY *)psStruct->pFunctionality)->secondaryOrder;
Expand Down
24 changes: 18 additions & 6 deletions src/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ void structureRepair(STRUCTURE *psStruct, DROID *psDroid, int buildRate)

static void refundFactoryBuildPower(STRUCTURE *psBuilding)
{
ASSERT_OR_RETURN(, psBuilding->isFactory(), "structure not a factory");
ASSERT_OR_RETURN(, psBuilding && psBuilding->isFactory(), "structure not a factory");
FACTORY *psFactory = &psBuilding->pFunctionality->factory;

if (psFactory->psSubject)
Expand Down Expand Up @@ -1667,6 +1667,10 @@ STRUCTURE *buildStructureDir(STRUCTURE_STATS *pStructureType, UDWORD x, UDWORD y
{
for (const STRUCTURE *psStruct : apsStructLists[playerNum])
{
if (!psStruct)
{
continue;
}
FLAG_POSITION *fp = nullptr;
if (psStruct->isFactory())
{
Expand Down Expand Up @@ -5990,7 +5994,7 @@ bool FlagIsFactory(const FLAG_POSITION *psCurrFlag)
//
FLAG_POSITION *FindFactoryDelivery(const STRUCTURE *Struct)
{
if (Struct->isFactory())
if (Struct && Struct->isFactory())
{
// Find the factories delivery point.
for (const auto& psFlag : apsFlagPosLists[Struct->player])
Expand All @@ -6016,6 +6020,10 @@ STRUCTURE *findDeliveryFactory(FLAG_POSITION *psDelPoint)

for (STRUCTURE* psCurr : apsStructLists[psDelPoint->player])
{
if (!psCurr)
{
continue;
}
if (psCurr->isFactory())
{
psFactory = &psCurr->pFunctionality->factory;
Expand All @@ -6041,7 +6049,7 @@ STRUCTURE *findDeliveryFactory(FLAG_POSITION *psDelPoint)
accrued but not used*/
void cancelProduction(STRUCTURE *psBuilding, QUEUE_MODE mode, bool mayClearProductionRun)
{
ASSERT_OR_RETURN(, psBuilding->isFactory(), "structure not a factory");
ASSERT_OR_RETURN(, psBuilding && psBuilding->isFactory(), "structure not a factory");

FACTORY *psFactory = &psBuilding->pFunctionality->factory;

Expand Down Expand Up @@ -6075,7 +6083,7 @@ void holdProduction(STRUCTURE *psBuilding, QUEUE_MODE mode)
{
FACTORY *psFactory;

ASSERT_OR_RETURN(, psBuilding->isFactory(), "structure not a factory");
ASSERT_OR_RETURN(, psBuilding && psBuilding->isFactory(), "structure not a factory");

psFactory = &psBuilding->pFunctionality->factory;

Expand Down Expand Up @@ -6104,7 +6112,7 @@ void holdProduction(STRUCTURE *psBuilding, QUEUE_MODE mode)
/*release a factory's production run from hold*/
void releaseProduction(STRUCTURE *psBuilding, QUEUE_MODE mode)
{
ASSERT_OR_RETURN(, psBuilding->isFactory(), "structure not a factory");
ASSERT_OR_RETURN(, psBuilding && psBuilding->isFactory(), "structure not a factory");

FACTORY *psFactory = &psBuilding->pFunctionality->factory;

Expand Down Expand Up @@ -6396,6 +6404,10 @@ void checkDeliveryPoints(UDWORD version)
{
for (STRUCTURE* psStruct : apsStructLists[inc])
{
if (!psStruct)
{
continue;
}
if (psStruct->isFactory())
{
//check the DP
Expand Down Expand Up @@ -6455,7 +6467,7 @@ void factoryLoopAdjust(STRUCTURE *psStruct, bool add)
{
FACTORY *psFactory;

ASSERT_OR_RETURN(, psStruct->isFactory(), "structure is not a factory");
ASSERT_OR_RETURN(, psStruct && psStruct->isFactory(), "structure is not a factory");
ASSERT_OR_RETURN(, psStruct->player == selectedPlayer, "should only be called for selectedPlayer");

psFactory = &psStruct->pFunctionality->factory;
Expand Down
2 changes: 1 addition & 1 deletion src/template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ void deleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, unsigned player, Q
}
for (STRUCTURE* psStruct : *psList)
{
if (psStruct->isFactory())
if (psStruct && psStruct->isFactory())
{
if (psStruct->pFunctionality == nullptr)
{
Expand Down

0 comments on commit c25e85c

Please sign in to comment.