NOAA-OWP / evapotranspiration

Other
3 stars 9 forks source link

time_step_size_s needs additional validation #40

Open hellkite500 opened 4 months ago

hellkite500 commented 4 months ago

https://github.com/NOAA-OWP/evapotranspiration/blob/80c1ab9189e6a9c131cea72b4e22b41bb9a5f177/src/bmi_pet.c#L768

The time_step_size_s parameter is used to set the BMI model time step, which is used in Update_until to determine how many Update steps to call. If this parameter isn't provided in the configuration, it is left uninitialized and leads to undefined behavior. For example, if the compiler assigns 0 for the uninitialized variable, then in Update_until there is a divide by 0, which can cause a crash, or worse, can make n_steps become inf (again, this is undefined behavior...) which causes an infinite loop.

This either needs to be a required parameter and validated to not be 0, or an optional value (also validated to not be 0) and a non-zero default assigned during initialization.

SnowHydrology commented 3 months ago

@hellkite500 Is there an automated way I can check for other variables that might exhibit this same behavior?