Bounds checking: string length shorter than declared size in ideal initialization code
(Originally reported at https://github.com/WRF-CMake/WRF/issues/4)
When compiling WRF with -fcheck=bounds then running ideal.exe fails with:
At line 19288 of file .../inc/nl_config.inc
Fortran runtime error: Actual string length is shorter than the declared one for dummy argument 'mminlu' (4/256)
It seems that lots of code is correctly handling strings, e.g.: https://github.com/wrf-model/WRF/blob/3ced231c6785c6d26615972a955634365e582db4/dyn_em/module_initialize_fire.F#L207-L209
However, there are cases which would trigger the runtime error: https://github.com/wrf-model/WRF/blob/3ced231c6785c6d26615972a955634365e582db4/dyn_em/module_initialize_ideal.F#L346
A grep for nl_set_mminlu reveals a few more.
I would highly recommend to turn all relevant runtime checks on at least during testing so that those issues can be caught early and definitely before new releases.
Perhaps this is a more robust way to zap (clear) a character string:
string = repeat(' ', len(string))
https://software.intel.com/en-us/fortran-compiler-18.0-developer-guide-and-reference-repeat
Craig
On Sep 24, 2018, at 4:53 PM, Maik Riechert [email protected] wrote:
(Originally reported at WRF-CMake#4)
When compiling WRF with -fcheck=bounds then running ideal.exe fails with:
At line 19288 of file .../inc/nl_config.inc Fortran runtime error: Actual string length is shorter than the declared one for dummy argument 'mminlu' (4/256)
It seems that lots of code is correctly handling strings, e.g.: https://github.com/wrf-model/WRF/blob/3ced231c6785c6d26615972a955634365e582db4/dyn_em/module_initialize_fire.F#L207-L209
However, there are cases which would trigger the runtime error: https://github.com/wrf-model/WRF/blob/3ced231c6785c6d26615972a955634365e582db4/dyn_em/module_initialize_ideal.F#L346
A grep for nl_set_mminlu reveals a few more.
I would highly recommend to turn all relevant runtime checks on at least during testing so that those issues can be caught early and definitely before new releases.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
Here are the others I found:
https://github.com/wrf-model/WRF/blob/3ced231c6785c6d26615972a955634365e582db4/dyn_em/module_wps_io_arw.F#L359-L371
https://github.com/wrf-model/WRF/blob/3ced231c6785c6d26615972a955634365e582db4/dyn_nmm/module_si_io_nmm.F#L613-L614
https://github.com/wrf-model/WRF/blob/3ced231c6785c6d26615972a955634365e582db4/dyn_em/module_initialize_heldsuarez.F#L228
I believe there is, a simple
string = ' '
should do the job.
On Mon, Sep 24, 2018 at 9:12 PM cmattocks [email protected] wrote:
Perhaps this is a more robust way to zap (clear) a character string:
string = repeat(' ', len(string))
https://software.intel.com/en-us/fortran-compiler-18.0-developer-guide-and-reference-repeat
Craig
On Sep 24, 2018, at 4:53 PM, Maik Riechert [email protected] wrote:
(Originally reported at WRF-CMake#4)
When compiling WRF with -fcheck=bounds then running ideal.exe fails with:
At line 19288 of file .../inc/nl_config.inc Fortran runtime error: Actual string length is shorter than the declared one for dummy argument 'mminlu' (4/256)
It seems that lots of code is correctly handling strings, e.g.:
https://github.com/wrf-model/WRF/blob/3ced231c6785c6d26615972a955634365e582db4/dyn_em/module_initialize_fire.F#L207-L209
However, there are cases which would trigger the runtime error:
https://github.com/wrf-model/WRF/blob/3ced231c6785c6d26615972a955634365e582db4/dyn_em/module_initialize_ideal.F#L346
A grep for nl_set_mminlu reveals a few more.
I would highly recommend to turn all relevant runtime checks on at least during testing so that those issues can be caught early and definitely before new releases.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/wrf-model/WRF/issues/631#issuecomment-424174665, or mute the thread https://github.com/notifications/unsubscribe-auth/AIHAkponqPfB3-Nzfm6Hwe_uHdFAifvkks5ueYMBgaJpZM4W3cDH .
Yes, good point - the two forms work the same way.
To prevent bounds overflows, one can do this (truncate input if necessary):
program testStrings implicit none character(len = 8) :: string character(len = 6) :: tooSmall character(len = 10) :: tooLarge character(len = 8) :: justRight
tooSmall = "123456" call setString(string, tooSmall) print *, "String too small: ", string
tooLarge = "1234567890" call setString(string, tooLarge) print *, "String too large: ", string
justRight = "12345678" call setString(string, justRight) print *, "String with correct length: ", string
contains
pure subroutine setString(string, value) implicit none character(len = *), intent(in out) :: string character(len = *), intent(in) :: value integer :: ls, lv ls = len(string) lv = len_trim(value) if (lv <= ls) then string = repeat(' ', ls) string(1:lv) = trim(value) else string = value(1:ls) end if end subroutine setString
end program testStrings
Craig
On Sep 25, 2018, at 8:17 AM, stacywalters [email protected] wrote:
I believe there is, a simple
string = ' '
should do the job.
On Mon, Sep 24, 2018 at 9:12 PM cmattocks [email protected] wrote:
Perhaps this is a more robust way to zap (clear) a character string:
string = repeat(' ', len(string))
https://software.intel.com/en-us/fortran-compiler-18.0-developer-guide-and-reference-repeat
Craig
On Sep 24, 2018, at 4:53 PM, Maik Riechert [email protected] wrote:
(Originally reported at WRF-CMake#4)
When compiling WRF with -fcheck=bounds then running ideal.exe fails with:
At line 19288 of file .../inc/nl_config.inc Fortran runtime error: Actual string length is shorter than the declared one for dummy argument 'mminlu' (4/256)
It seems that lots of code is correctly handling strings, e.g.:
https://github.com/wrf-model/WRF/blob/3ced231c6785c6d26615972a955634365e582db4/dyn_em/module_initialize_fire.F#L207-L209
However, there are cases which would trigger the runtime error:
https://github.com/wrf-model/WRF/blob/3ced231c6785c6d26615972a955634365e582db4/dyn_em/module_initialize_ideal.F#L346
A grep for nl_set_mminlu reveals a few more.
I would highly recommend to turn all relevant runtime checks on at least during testing so that those issues can be caught early and definitely before new releases.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/wrf-model/WRF/issues/631#issuecomment-424174665, or mute the thread https://github.com/notifications/unsubscribe-auth/AIHAkponqPfB3-Nzfm6Hwe_uHdFAifvkks5ueYMBgaJpZM4W3cDH .
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.