disallow empty value strings when setting numbers in CCTK_ParameterSet

Issue #1544 closed
Roland Haas created an issue

Currently due to the way strtol and strtod work one can do

CCTK_ParameterSet("cctk_itlast", "Cactus", "")

which return 0 (all is fine) and sets cctk_itlast to 0 (rather than failing with -6 "invalid string").

The attached patch checks that the parameter value string is not empty.

This cannot happen from inside of parfiles since the parser disallows it. It can happen when using the Trigger thorn.

Keyword:

Comments (6)

  1. Erik Schnetter
    • removed comment

    According to the strtol documentation:

         If endptr is not NULL, strtol() stores the address of the first invalid
         character in *endptr.  If there were no digits at all, however, strtol()
         stores the original value of str in *endptr.  (Thus, if *str is not `\0'
         but **endptr is `\0' on return, the entire string was valid.)
    

    Thus it should not be necessary to check whether the whole string consists of whitespace.

  2. Roland Haas reporter
    • removed comment

    Much simpler. Many thanks for th suggestion. Attached please find an updated patch.

  3. Log in to comment