-
Notifications
You must be signed in to change notification settings - Fork 629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core] Add nullness checking from static analysis #6361
base: base
Are you sure you want to change the base?
[core] Add nullness checking from static analysis #6361
Conversation
|
||
int32 CE = (int32)(80.f / damageMod * Damage); | ||
int32 VE = (int32)(240.f / damageMod * Damage); | ||
if (m_EnmityHolder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we invert this so the whole function isn't indented?
if m_EnmityHolder == nullptr, return
@@ -340,7 +340,7 @@ void CMeritPoints::RaiseMerit(MERIT_TYPE merit) | |||
{ | |||
Merit_t* PMerit = GetMeritPointer(merit); | |||
|
|||
if (m_MeritPoints >= PMerit->next && PMerit->count < PMerit->upgrade && GetMeritCountInSameCategory(merit) < meritCatInfo[GetMeritCategory(merit)].MaxPoints) | |||
if (PMerit && m_MeritPoints >= PMerit->next && PMerit->count < PMerit->upgrade && GetMeritCountInSameCategory(merit) < meritCatInfo[GetMeritCategory(merit)].MaxPoints) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly here, should we be doing if PMerit is nullptr, message, and bail out early
instead of rolling it into all of these other checks?
@@ -372,30 +372,32 @@ void CMeritPoints::RaiseMerit(MERIT_TYPE merit) | |||
void CMeritPoints::LowerMerit(MERIT_TYPE merit) | |||
{ | |||
Merit_t* PMerit = GetMeritPointer(merit); | |||
|
|||
if (PMerit->count > 0) | |||
if (PMerit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, check and bail out please
@@ -4855,7 +4855,7 @@ void SmallPacket0x077(map_session_data_t* const PSession, CCharEntity* const PCh | |||
{ | |||
case 0: // party | |||
{ | |||
if (PChar->PParty != nullptr && PChar->PParty->GetLeader() == PChar) | |||
if (PChar && PChar->PParty != nullptr && PChar->PParty->GetLeader() == PChar) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, we can check PChar once before the switch and then continue afterwards with impunity
@@ -1300,7 +1300,7 @@ void CZoneEntities::PushPacket(CBaseEntity* PEntity, GLOBAL_MESSAGE_TYPE message | |||
case CHAR_INRANGE_SELF: // NOTE!!!: This falls through to CHAR_INRANGE so both self and the local area get the packet | |||
{ | |||
TracyZoneCString("CHAR_INRANGE_SELF"); | |||
if (PEntity->objtype == TYPE_PC) | |||
if (PEntity && PEntity->objtype == TYPE_PC) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theres part of a PEntity check in the GM section, but the PEntity check can go with or next to the packet check at the very start
I affirm:
What does this pull request do?
Adds some nullness checking I found in a static code analysis
Steps to test these changes
Test things effected, see no change