-
Notifications
You must be signed in to change notification settings - Fork 229
bugfix(controlbar): Fix possible divisions by zero in Control Bar code #2867
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2702,8 +2702,7 @@ void Player::resetRank() | |
| m_rankLevel = 1; | ||
| m_skillPoints = 0; | ||
| const RankInfo* nextRank = TheRankInfoStore->getRankInfo(m_rankLevel+1); | ||
| m_levelUp = nextRank ? nextRank->m_skillPointsNeeded : INT_MAX; | ||
| m_levelDown = 0; | ||
| setSafeLevels(nextRank ? nextRank->m_skillPointsNeeded : INT_MAX, 0); | ||
| m_sciences.clear(); | ||
| m_sciencePurchasePoints = getPlayerTemplate() ? getPlayerTemplate()->getIntrinsicSciencePurchasePoints() : 0; | ||
| const RankInfo* curRank = TheRankInfoStore->getRankInfo(m_rankLevel); | ||
|
|
@@ -2762,7 +2761,8 @@ Bool Player::setRankLevel(Int newLevel) | |
| } | ||
|
|
||
| const RankInfo* nextRank = TheRankInfoStore->getRankInfo(newLevel + 1); | ||
| m_levelUp = nextRank ? nextRank->m_skillPointsNeeded : INT_MAX; | ||
| setSafeLevels(nextRank ? nextRank->m_skillPointsNeeded : INT_MAX, m_levelDown); | ||
|
|
||
| m_rankLevel = newLevel; | ||
|
|
||
| DEBUG_ASSERTCRASH(m_skillPoints >= m_levelDown && m_skillPoints < m_levelUp, ("hmm, wrong")); | ||
|
|
@@ -2788,6 +2788,22 @@ Bool Player::setRankLevel(Int newLevel) | |
| return true; | ||
| } | ||
|
|
||
| //============================================================================= | ||
| void Player::setSafeLevels(Int levelUp, Int levelDown) | ||
| { | ||
| if (levelUp == levelDown) | ||
| { | ||
| // TheSuperHackers @bugfix Prevent possible division by zero in the control bar code. | ||
| m_levelUp = INT_MAX; | ||
| m_levelDown = 0; | ||
| } | ||
|
Comment on lines
+2794
to
+2799
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Equal adjacent Prompt To Fix With AIThis is a comment left during a code review.
Path: GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
Line: 2794-2799
Comment:
**Do not terminalize duplicates**
Equal adjacent `SkillPointsNeeded` values are valid custom-rank input for the crash case this code handles. When a player reaches rank N and rank N+1 has the same threshold, this branch replaces the next threshold with `INT_MAX`; `addSkillPoints()` can then never advance the player to rank N+1 even though the threshold is already met. Handle a zero-width transition without converting it into the terminal-rank sentinel.
How can I resolve this? If you propose a fix, please make it concise. |
||
| else | ||
| { | ||
| m_levelUp = levelUp; | ||
| m_levelDown = levelDown; | ||
| } | ||
| } | ||
|
|
||
| //============================================================================= | ||
| Bool Player::hasScience(ScienceType t) const | ||
| { | ||
|
|
@@ -4588,6 +4604,5 @@ void Player::xfer( Xfer *xfer ) | |
| // ------------------------------------------------------------------------------------------------ | ||
| void Player::loadPostProcess() | ||
| { | ||
|
|
||
| setSafeLevels(m_levelUp, m_levelDown); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.