In module_diag_hailcast.F90, KBAS=1 is possible, and this reads out of bounds a few lines later.
SamuelTrahanNOAA opened this issue · 1 comments
SamuelTrahanNOAA commented
Describe the bug
You will find this around line 790 or so in module_diag_hailcast.F90:
DO k=1,nz
... more stuff ...
IF ((cwitot .ge. 1.E-12) .and. (k .lt. KBAS)) THEN
KBAS = k
ENDIF
ENDDO
It can set KBAS=1
when the loop reaches k=1
.
Later:
ELSE IF ((k.ge.KBAS+1).AND.(RWA_adiabat(k).ge.1.E-12)) THEN
RWA_new(k) = RWA_adiabat(k)*(h1d(k)-h1d(k-1)) - RWA_new(k-1)
IF (RWA_new(k).LT.0) RWA_new(k) = 0.
ENDIF
...
DO k=KBAS,nz
RWA_new(k) = RWA_new(k) / (h1d(k)-h1d(k-1))
ENDDO
If KBAS=1, then the first step of this loop will access h1d(k-1)
To Reproduce
See ufs-community/ufs-weather-model#2065 for a test case.
Expected behavior
Don't read out-of-bounds
System Environment
WCOSS2 Dogwood.
Additional context
Test case fails on WCOSS2 dogwood but passes on Hera.
ywangwof commented
The changes look good to me.