fv3atm
fv3atm copied to clipboard
Bug in GFS_typedefs.F90? Should Model%nto and Model%nto2 always be initialized?
See https://github.com/NOAA-EMC/fv3atm/blob/a9364591091c836984a40107729720705847c195/ccpp/data/GFS_typedefs.F90#L5181
Model%nto
and Model%nto2
are only initialized if the CPP directive MULTI_GASES
is set. But these variables always exist (see lines 1490-1491) and therefore remain uninitialized.
In lines 5398-5399, they are used to set up the label_dtend_tracer
array if ldiag3d
is true. Since ldiag3d
can be true without MULTI_GASES
being set, it looks like uninitialized values of nto
and nto2
are passed to that routine. Unless I am not seeing it. Depending on the system you are on, this can have bad consequences. Example: on my laptop and on Nautilus (a DoD Penguin Linux system), they both always have value zero. That results in double free memory corruption errors later in the add_dtend
calls. On Narwhal (a DoD Cray system), they have very large but different integer values that result in out of bounds errors. This is with NEPTUNE and not with the UFS, but if I read the code in GFS_typedefs
correctly, the bug seems to be there, too?