Skip to content

Fix: Zero-initialize particle in orbital_elements example to prevent undefined behavior#910

Open
yuanzui-cf wants to merge 1 commit into
hannorein:mainfrom
yuanzui-cf:fix/example-uninitialized-particle
Open

Fix: Zero-initialize particle in orbital_elements example to prevent undefined behavior#910
yuanzui-cf wants to merge 1 commit into
hannorein:mainfrom
yuanzui-cf:fix/example-uninitialized-particle

Conversation

@yuanzui-cf
Copy link
Copy Markdown

In examples/orbital_elements/problem.c, struct reb_particle p is declared without initialization.

While this happens to work on some systems due to zero-filled memory pages, on some machines (such as my MacBook M4) it leaves garbage values in stack memory, leading to incorrect relative orbit calculations.

Added = {0} to properly zero-initialize the struct, preventing undefined behavior and matching the safe pattern used in other examples in this repository.

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.

1 participant