Skip to content

fix: avoid taking address of loop variables #2430

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
Apr 29, 2025

Conversation

tenthirtyam
Copy link
Contributor

Description

Refactored loops in availableScsiDisk and diskSpecForCreate to correctly obtain pointers to slice elements.

Previously, the code was taking the address of the loop iteration variable (e.g., &d), which is unsafe as the variable is reused. The loops now access the element directly from the slice by index (e.g., &disks[i]) before taking the address, ensuring the pointer references the correct underlying data.

Refactored loops in `availableScsiDisk` and `diskSpecForCreate` to correctly obtain pointers to slice elements.

Previously, the code was taking the address of the loop iteration variable (e.g., `&d`), which is unsafe as the variable is reused.
The loops now access the element directly from the slice by index (e.g., `&disks[i]`) before taking the address, ensuring the pointer
references the correct underlying data.

Signed-off-by: Ryan Johnson <[email protected]>
@tenthirtyam tenthirtyam added technical-debt Technical Debt refactor Refactor labels Apr 27, 2025
@tenthirtyam tenthirtyam added this to the v2.13.0 milestone Apr 27, 2025
@tenthirtyam tenthirtyam requested a review from spacegospod April 27, 2025 01:52
@tenthirtyam tenthirtyam self-assigned this Apr 27, 2025
@tenthirtyam tenthirtyam requested a review from a team as a code owner April 27, 2025 01:52
@tenthirtyam tenthirtyam marked this pull request as draft April 27, 2025 02:06
@tenthirtyam tenthirtyam removed the request for review from spacegospod April 27, 2025 02:06
@tenthirtyam tenthirtyam removed this from the v2.13.0 milestone Apr 27, 2025
@tenthirtyam tenthirtyam requested a review from spacegospod April 27, 2025 02:43
@tenthirtyam tenthirtyam added this to the v2.13.0 milestone Apr 27, 2025
@tenthirtyam tenthirtyam marked this pull request as ready for review April 27, 2025 02:44
@tenthirtyam tenthirtyam added the needs-review Needs Review label Apr 27, 2025
@tenthirtyam tenthirtyam removed the needs-review Needs Review label Apr 29, 2025
@tenthirtyam tenthirtyam merged commit f94f858 into main Apr 29, 2025
8 checks passed
@tenthirtyam tenthirtyam deleted the fix/loop-variable-pointer branch April 29, 2025 21:10
Copy link

This functionality has been released in v2.13.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Refactor technical-debt Technical Debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants