Skip to content

[GEN][ZH] Prevent using uninitialized memory 'result' in PartitionData::calcMaxCoiForShape() #1133

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

Merged
merged 1 commit into from
Jun 22, 2025

Conversation

xezon
Copy link

@xezon xezon commented Jun 21, 2025

This change prevents using uninitialized memory 'result' in PartitionData::calcMaxCoiForShape() to make the compiler happy.

This is effectively just a refactor because this is impossible to happen because we expect passing valid enum values only. Handling default case is just courtesy.

GeneralsMD\Code\GameEngine\Source\GameLogic\Object\PartitionManager.cpp(2181): warning C6001: Using uninitialized memory 'result'.

@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing labels Jun 21, 2025
@@ -2175,8 +2175,12 @@ Int PartitionData::calcMaxCoiForShape(GeometryType geom, Real majorRadius, Real
Real diagonal = (Real)(sqrtf(majorRadius*majorRadius + minorRadius*minorRadius));
Int cells = ThePartitionManager->worldToCellDist(diagonal*2) + 1;
result = cells * cells;
break;

Choose a reason for hiding this comment

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

This break is already added in #1135.

Copy link
Author

Choose a reason for hiding this comment

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

Yes. It will be removed one the second one to be merged.

@@ -2168,8 +2168,12 @@ Int PartitionData::calcMaxCoiForShape(GeometryType geom, Real majorRadius, Real
Real diagonal = (Real)(sqrtf(majorRadius*majorRadius + minorRadius*minorRadius));
Int cells = ThePartitionManager->worldToCellDist(diagonal*2) + 1;
result = cells * cells;
break;

Choose a reason for hiding this comment

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

This break is already added in #1135.

};
static_assert(GEOMETRY_NUM_TYPES == 3, "GEOMETRY_NUM_TYPES has changed");

Choose a reason for hiding this comment

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

Why is this added?

Copy link
Author

Choose a reason for hiding this comment

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

This static assert will trigger if the GEOMETRY_NUM_TYPES was changed and show that this switch case needs updating.

@xezon xezon merged commit be7f0d4 into TheSuperHackers:main Jun 22, 2025
14 checks passed
@xezon xezon deleted the xezon/staticanalysis2/041 branch June 22, 2025 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants