Skip to content
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

Open
wants to merge 1 commit into
base: base
Choose a base branch
from

Conversation

WinterSolstice8
Copy link
Member

I affirm:

  • I understand that if I do not agree to the following points by completing the checkboxes my PR will be ignored.
  • I understand I should leave resolving conversations to the LandSandBoat team so that reviewers won't miss what was said.
  • I have read and understood the Contributing Guide and the Code of Conduct.
  • I have tested my code and the things my code has changed since the last commit in the PR and will test after any later commits.

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


int32 CE = (int32)(80.f / damageMod * Damage);
int32 VE = (int32)(240.f / damageMod * Damage);
if (m_EnmityHolder)
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants