Skip to content

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

Merged
hannorein merged 1 commit into
hannorein:mainfrom
yuanzui-cf:fix/example-uninitialized-particle
May 13, 2026
Merged

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

Conversation

@yuanzui-cf

Copy link
Copy Markdown
Contributor

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.

@hannorein hannorein merged commit e780379 into hannorein:main May 13, 2026
24 checks passed
@yuanzui-cf yuanzui-cf deleted the fix/example-uninitialized-particle branch May 13, 2026 15:48
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