Skip to content

Commit f7f26a4

Browse files
authored
[GEN][ZH] Fix dereferencing NULL pointer 'victimObj' in WeaponTemplate::estimateWeaponTemplateDamage() (#1093)
1 parent 795c025 commit f7f26a4

File tree

2 files changed

+43
-65
lines changed
  • GeneralsMD/Code/GameEngine/Source/GameLogic/Object
  • Generals/Code/GameEngine/Source/GameLogic/Object

2 files changed

+43
-65
lines changed

Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,16 @@ Real WeaponTemplate::estimateWeaponTemplateDamage(
567567
return 0.0f;
568568
}
569569

570+
const Real damageAmount = getPrimaryDamage(bonus);
571+
if ( victimObj == NULL )
572+
{
573+
return damageAmount;
574+
}
575+
570576
DamageType damageType = getDamageType();
571577
DeathType deathType = getDeathType();
572578

573-
if (victimObj && victimObj->isKindOf(KINDOF_SHRUBBERY))
579+
if ( victimObj->isKindOf(KINDOF_SHRUBBERY) )
574580
{
575581
if (deathType == DEATH_BURNED)
576582
{
@@ -584,7 +590,7 @@ Real WeaponTemplate::estimateWeaponTemplateDamage(
584590
}
585591

586592
// this stays, even if ALLOW_SURRENDER is not defed, since flashbangs still use 'em
587-
if (damageType == DAMAGE_SURRENDER || m_allowAttackGarrisonedBldgs)
593+
if ( damageType == DAMAGE_SURRENDER || m_allowAttackGarrisonedBldgs )
588594
{
589595
ContainModuleInterface* contain = victimObj->getContain();
590596
if( contain && contain->getContainCount() > 0 && contain->isGarrisonable() && !contain->isImmuneToClearBuildingAttacks() )
@@ -594,42 +600,25 @@ Real WeaponTemplate::estimateWeaponTemplateDamage(
594600
}
595601
}
596602

597-
if( victimObj )
603+
if( victimObj->isKindOf(KINDOF_MINE) && damageType == DAMAGE_DISARM )
598604
{
599-
if( victimObj->isKindOf(KINDOF_MINE) && damageType == DAMAGE_DISARM )
600-
{
601-
// this is just a nonzero value, to ensure we can target mines with disarm weapons, regardless...
602-
return 1.0f;
603-
}
604-
if( damageType == DAMAGE_DEPLOY && !victimObj->isAirborneTarget() )
605-
{
606-
return 1.0f;
607-
}
605+
// this is just a nonzero value, to ensure we can target mines with disarm weapons, regardless...
606+
return 1.0f;
607+
}
608+
if( damageType == DAMAGE_DEPLOY && !victimObj->isAirborneTarget() )
609+
{
610+
return 1.0f;
608611
}
609612

610613
//@todo Kris need to examine the DAMAGE_HACK type for damage estimation purposes.
611614
//Likely this damage type will have threat implications that won't properly be dealt with until resolved.
612615

613-
// const Coord3D* sourcePos = sourceObj->getPosition();
614-
if (victimPos == NULL)
615-
{
616-
victimPos = victimObj->getPosition();
617-
}
618-
619-
Real damageAmount = getPrimaryDamage(bonus);
620-
if (victimObj == NULL)
621-
{
622-
return damageAmount;
623-
}
624-
else
625-
{
626-
DamageInfoInput damageInfo;
627-
damageInfo.m_damageType = damageType;
628-
damageInfo.m_deathType = deathType;
629-
damageInfo.m_sourceID = sourceObj->getID();
630-
damageInfo.m_amount = damageAmount;
631-
return victimObj->estimateDamage(damageInfo);
632-
}
616+
DamageInfoInput damageInfo;
617+
damageInfo.m_damageType = damageType;
618+
damageInfo.m_deathType = deathType;
619+
damageInfo.m_sourceID = sourceObj->getID();
620+
damageInfo.m_amount = damageAmount;
621+
return victimObj->estimateDamage(damageInfo);
633622
}
634623

635624
//-------------------------------------------------------------------------------------------------

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,16 @@ Real WeaponTemplate::estimateWeaponTemplateDamage(
580580
return 0.0f;
581581
}
582582

583+
const Real damageAmount = getPrimaryDamage(bonus);
584+
if ( victimObj == NULL )
585+
{
586+
return damageAmount;
587+
}
588+
583589
DamageType damageType = getDamageType();
584590
DeathType deathType = getDeathType();
585591

586-
if (victimObj && victimObj->isKindOf(KINDOF_SHRUBBERY))
592+
if ( victimObj->isKindOf(KINDOF_SHRUBBERY) )
587593
{
588594
if (deathType == DEATH_BURNED)
589595
{
@@ -610,7 +616,7 @@ Real WeaponTemplate::estimateWeaponTemplateDamage(
610616

611617

612618

613-
if (damageType == DAMAGE_SURRENDER || m_allowAttackGarrisonedBldgs)
619+
if ( damageType == DAMAGE_SURRENDER || m_allowAttackGarrisonedBldgs )
614620
{
615621
ContainModuleInterface* contain = victimObj->getContain();
616622
if( contain && contain->getContainCount() > 0 && contain->isGarrisonable() && !contain->isImmuneToClearBuildingAttacks() )
@@ -620,46 +626,29 @@ Real WeaponTemplate::estimateWeaponTemplateDamage(
620626
}
621627
}
622628

623-
if( victimObj )
629+
if( damageType == DAMAGE_DISARM )
624630
{
625-
if( damageType == DAMAGE_DISARM )
626-
{
627-
if( victimObj->isKindOf( KINDOF_MINE ) || victimObj->isKindOf( KINDOF_BOOBY_TRAP ) || victimObj->isKindOf( KINDOF_DEMOTRAP ) )
628-
{
629-
// this is just a nonzero value, to ensure we can target mines with disarm weapons, regardless...
630-
return 1.0f;
631-
}
632-
return 0.0f;
633-
}
634-
if( damageType == DAMAGE_DEPLOY && !victimObj->isAirborneTarget() )
631+
if( victimObj->isKindOf( KINDOF_MINE ) || victimObj->isKindOf( KINDOF_BOOBY_TRAP ) || victimObj->isKindOf( KINDOF_DEMOTRAP ) )
635632
{
633+
// this is just a nonzero value, to ensure we can target mines with disarm weapons, regardless...
636634
return 1.0f;
637635
}
636+
return 0.0f;
637+
}
638+
if( damageType == DAMAGE_DEPLOY && !victimObj->isAirborneTarget() )
639+
{
640+
return 1.0f;
638641
}
639642

640643
//@todo Kris need to examine the DAMAGE_HACK type for damage estimation purposes.
641644
//Likely this damage type will have threat implications that won't properly be dealt with until resolved.
642645

643-
// const Coord3D* sourcePos = sourceObj->getPosition();
644-
if (victimPos == NULL)
645-
{
646-
victimPos = victimObj->getPosition();
647-
}
648-
649-
Real damageAmount = getPrimaryDamage(bonus);
650-
if (victimObj == NULL)
651-
{
652-
return damageAmount;
653-
}
654-
else
655-
{
656-
DamageInfoInput damageInfo;
657-
damageInfo.m_damageType = damageType;
658-
damageInfo.m_deathType = deathType;
659-
damageInfo.m_sourceID = sourceObj->getID();
660-
damageInfo.m_amount = damageAmount;
661-
return victimObj->estimateDamage(damageInfo);
662-
}
646+
DamageInfoInput damageInfo;
647+
damageInfo.m_damageType = damageType;
648+
damageInfo.m_deathType = deathType;
649+
damageInfo.m_sourceID = sourceObj->getID();
650+
damageInfo.m_amount = damageAmount;
651+
return victimObj->estimateDamage(damageInfo);
663652
}
664653

665654
//-------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)