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
if (i2 < 0) then
fac_b =0d0end ifif (i3 < 0) then
fac_c =0d0end if
combin = thrcofa(i1) + fac_b * thrcofb(i2) + fac_c * thrcofc(i3)
Here, i2 and i3 can obviously take values below 1, but they are used to access the arrays thrcofb and thrcofc whose first index is 1. This is undefined behaviour and can cause segmentation faults.
Even if this currently doesn't cause any issues, I'd still suggest to avoid these accesses, since they will make debugging of potential other problems much harder.
The text was updated successfully, but these errors were encountered:
I think a correct way to handle these cases is the following
if (i2 < 1) then
combin2 =0d0else
combin2 = fac_b * thrcofb(i2)
end ifif (i3 < 1) then
combin3 =0d0else
combin3 = fac_c * thrcofc(i3)
end if
combin = thrcofa(i1) + combin2 + combin3
where combin2 and combin3 are real(8). I've added a test for pure BB mode with comparisons with NaMaster (see PR #82). The above code (not yet implemented in PR #82) is still "physically" correct but prevent access to undefined array values. Does it look fine for you ?
While running benchmarks on the code I noticed a block in hte Fortran sources that looks dangerous to me: https://github.com/simonsobs/pspy/blob/1d5d8734f489c6a15fe6ee53d8d61b25478fd9b4/pspy/mcm_fortran/mcm_fortran.f90#L77C1-L86C1
Here,
i2
andi3
can obviously take values below 1, but they are used to access the arraysthrcofb
andthrcofc
whose first index is 1. This is undefined behaviour and can cause segmentation faults.Even if this currently doesn't cause any issues, I'd still suggest to avoid these accesses, since they will make debugging of potential other problems much harder.
The text was updated successfully, but these errors were encountered: