You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: dedx_get_ion_list() returns a thread-unsafe function-local static buffer #113
Part of #108 (health-review epic). Sub-concern of the broader thread-safety effort in #86.
Problem
For Bethe/default programs, dedx_get_ion_list() builds and returns a pointer to a function-local static array:
constint*dedx_get_ion_list(intprogram) {
if (program==DEDX_BETHE_EXT00||program==DEDX_DEFAULT) {
staticinttemp[113], i;
for (i=0; i<112; i++) temp[i] =i+1;
temp[112] =-1; // stopperreturntemp; // TODO: Hey Jakob, er det her lovligt eller et nyt mem leak?
} elsereturndedx_program_available_ions[program];
}
Two problems:
Not thread-safe — concurrent callers race on the shared static buffer, and the returned pointer aliases mutable shared state.
The leftover Danish // TODO … mem leak? comment indicates this was never resolved and should not ship.
Proposed change
Return a pointer to a static const precomputed, -1-terminated table (built once at compile time or guarded init), matching the immutable-static contract of the other dedx_get_*_list() functions. Remove the TODO comment.
Acceptance criteria
dedx_get_ion_list() returns a pointer to immutable, read-only data for all programs (no per-call mutation of shared state).
Behavior is unchanged: a -1-terminated list of ions 1..112 for Bethe/default.
The Danish TODO comment is gone.
No regression in test_initialize / list-related tests.
Activity