这是indexloc提供的服务,不要输入任何密码
Skip to content

Fix use of uninitialized variable in PowerupManager #5459

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

Conversation

nyllet
Copy link
Contributor

@nyllet nyllet commented Jun 15, 2025

Also avoid a potenial null pointer dereference
Remove two unused includes
Minor cleanups

Agreement

By creating a pull request in stk-code, you hereby agree to dual-license your contribution as
GNU General Public License version 3 or any later version and
Mozilla Public License version 2 or any later version.

This includes your previous contribution(s) under the same name of contributor.

Keep the above statement in the pull request comment for agreement.

Also avoid a potenial null pointer dereference
Remove two unused includes
Minor cleanups
Copy link
Collaborator

@Alayan-stk-2 Alayan-stk-2 left a comment

Choose a reason for hiding this comment

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

Thank you for the PR!

Please adjust the mentioned stylistic elements and it can be merged.

@@ -219,7 +216,7 @@ void PowerupManager::WeightsData::reset()
void PowerupManager::WeightsData::readData(int num_karts, const XMLNode *node)
{
m_num_karts = num_karts;
for (unsigned int i = 0; i < node->getNumNodes(); i++)
for (unsigned int i = 0; i < node->getNumNodes(); ++i)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Leave i++ in loops. The vast, vast majority of loops in the STK code base use post-increment notation, so this change creates inconsistencies.

In for loops, both pre-increment and post-increment will generate exactly the same code, so this is purely a stylistic matter.

@@ -232,12 +229,19 @@ void PowerupManager::WeightsData::readData(int num_karts, const XMLNode *node)

// Keep a reference for shorter access to the list
std::vector<int> &l = m_weights_for_section.back();
for(unsigned int i=0; i<l_string.size(); i++)
for(unsigned int j=0; j < l_string.size(); ++j)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same remark about ++j vs j++

Switching to j instead of i is definitely good for code clarity.

@Alayan-stk-2 Alayan-stk-2 merged commit f5f767c into supertuxkart:master Jun 16, 2025
21 checks passed
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.

2 participants