Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect check for out-of-bounds in State_SetScalar #838

Closed
SamuelTrahanNOAA opened this issue May 20, 2024 · 2 comments · Fixed by ufs-community/ufs-weather-model#2355
Closed
Labels
bug Something isn't working

Comments

@SamuelTrahanNOAA
Copy link
Contributor

SamuelTrahanNOAA commented May 20, 2024

Description

Bug encountered and investigated by @zhanglikate with debugging help from @DusanJovic-NOAA and myself. Credit goes mostly to zhanglikate who did a fantastic amount of debugging and testing in an impressively short time.

There is an out-of-bounds access (element 0) if one forgets to set these variables in ufs.configure:

  • flds_scalar_index_nx
  • flds_scalar_index_ny
  • flds_scalar_index_ntile

This bug is in State_SetScalar here in cpl/module_cplscalars.F90:

       if (scalar_id < 0 .or. scalar_id > flds_scalar_num) then ! <--- bug is here, not detecting scalar_id=0
          call ESMF_LogWrite(trim(subname)//": ERROR in scalar_id", ESMF_LOGMSG_INFO)
          rc = ESMF_FAILURE
          return
       endif
       farrayptr(scalar_id,1) = scalar_value  ! <--- crash is here with scalar_id=0

When one of the three flds_scalar_index_ variables is missing, scalar_id is 0. The "if" block doesn't catch it because it looks for scalar_id < 0 instead of scalar_id <= 0

To Reproduce:

What compilers/machines are you seeing this with?
Irrelevant. The bug is clear in the code.

Give explicit steps to reproduce the behavior.

  1. Forget to set flds_scalar_index_ntile
  2. Compile in debug mode
  3. Run a coupled case
  4. Witness the crash

Additional context

The bug started with this commit:

Output

The stack trace:

  0: forrtl: severe (408): fort: (3): Subscript #1 of the array FARRAYPTR has value 0 which is less than the lower bound of 1
   0:
   0: Image              PC                Routine            Line        Source
   0: ufs_model.x        00000000154A2F7F  Unknown               Unknown  Unknown
   0: ufs_model.x        0000000004277D04  module_cplscalars         124  module_cplscalars.F90
   0: ufs_model.x        000000000423F623  module_fcst_grid_         518  module_fcst_grid_comp.F90
   0: ufs_model.x        0000000000AA0B84  Unknown               Unknown  Unknown
   0: ufs_model.x        0000000000AA472F  Unknown               Unknown  Unknown
   0: ufs_model.x        000000000095097A  Unknown               Unknown  Unknown
   0: ufs_model.x        00000000011EDB99  Unknown               Unknown  Unknown
   0: ufs_model.x        0000000000AA1FCA  Unknown               Unknown  Unknown
   0: ufs_model.x        00000000009701B0  Unknown               Unknown  Unknown
   0: ufs_model.x        0000000000CA1351  Unknown               Unknown  Unknown
   0: ufs_model.x        000000000425983F  module_fcst_grid_        1266  module_fcst_grid_comp.F90
   0: ufs_model.x        0000000000AA0B84  Unknown               Unknown  Unknown
   0: ufs_model.x        0000000000AA472F  Unknown               Unknown  Unknown
   0: ufs_model.x        0000000000950B87  Unknown               Unknown  Unknown
   0: ufs_model.x        00000000011EDB99  Unknown               Unknown  Unknown
   0: ufs_model.x        0000000000AA1FCA  Unknown               Unknown  Unknown
   0: ufs_model.x        00000000009701B0  Unknown               Unknown  Unknown
   0: ufs_model.x        0000000000CA1351  Unknown               Unknown  Unknown
   0: ufs_model.x        0000000004224D4C  fv3atm_cap_mod_mp         997  fv3_cap.F90
   0: ufs_model.x        00000000006B00D8  Unknown               Unknown  Unknown
   0: ufs_model.x        00000000006B003A  Unknown               Unknown  Unknown
   0: ufs_model.x        00000000006B06E3  Unknown               Unknown  Unknown
   0: ufs_model.x        00000000004843AB  Unknown               Unknown  Unknown
   0: ufs_model.x        00000000041F0296  Unknown               Unknown  Unknown
   0: ufs_model.x        0000000000AA0B84  Unknown               Unknown  Unknown
   0: ufs_model.x        0000000000AA472F  Unknown               Unknown  Unknown
   0: ufs_model.x        000000000095097A  Unknown               Unknown  Unknown
   0: ufs_model.x        00000000011EDB99  Unknown               Unknown  Unknown
   0: ufs_model.x        0000000000AA1FCA  Unknown               Unknown  Unknown
   0: ufs_model.x        00000000009701B0  Unknown               Unknown  Unknown
@SamuelTrahanNOAA SamuelTrahanNOAA added the bug Something isn't working label May 20, 2024
@SamuelTrahanNOAA
Copy link
Contributor Author

Pinging @DeniseWorthen, who knows the relevant section of code well.

zhanglikate added a commit to zhanglikate/ufs-weather-model that referenced this issue May 21, 2024
zhanglikate added a commit to zhanglikate/ufs-weather-model that referenced this issue May 21, 2024
…c_physics

    Upp CATChem grib2 output

    Update configure files for S2S run due to the issue in
    NOAA-EMC/fv3atm#838
@DeniseWorthen
Copy link
Collaborator

Thanks for the work on this while I was away. I agree the check should be <=0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants