Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,11 @@ Bool WeaponSet::setWeaponLock( WeaponSlotType weaponSlot, WeaponLockType lockTyp
return false;
}

if (static_cast<UnsignedInt>(weaponSlot) >= ARRAY_SIZE(m_weapons))
{
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a DEBUG_CRASH maybe warranted here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind adding it, but I don't see the value myself.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can help warn of invalid data?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can help warn of invalid data?

What is the value of the warning? Is there an action we could or should take if we know that this code was executed?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was just considering if there was the possibility of invalid ini data getting this far, but it likely doesn't.

You could also simplify this to weaponSlot >= WEAPONSLOT_COUNT

@Caball009 Caball009 Oct 16, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was just considering if there was the possibility of invalid ini data getting this far, but it likely doesn't.

Not that I'm aware of.

You could also simplify this to weaponSlot >= WEAPONSLOT_COUNT

This doesn't catch negative numbers (WeaponSlotType's underlying type is signed). It also requires you to look up that ARRAY_SIZE(m_weapons) == WEAPONSLOT_COUNT.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most of the code already uses WEAPONSLOT_COUNT in this context, but it is also fair on the unsigned side of it.

}

// Verify the asked for weapon exists , choose it, and then lock it as chosen until unlocked
// the old code was just plain wrong. (look at it in perforce and you'll see...)
if (m_weapons[weaponSlot] != nullptr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,11 @@ Bool WeaponSet::setWeaponLock( WeaponSlotType weaponSlot, WeaponLockType lockTyp
return false;
}

if (static_cast<UnsignedInt>(weaponSlot) >= ARRAY_SIZE(m_weapons))
{
return false;
}

// Verify the asked for weapon exists , choose it, and then lock it as chosen until unlocked
// the old code was just plain wrong. (look at it in perforce and you'll see...)
if (m_weapons[weaponSlot] != nullptr)
Expand Down
Loading