diff options
author | rhaas <rhaas@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2014-02-13 02:11:56 +0000 |
---|---|---|
committer | rhaas <rhaas@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2014-02-13 02:11:56 +0000 |
commit | e2c5b6aac587c70b8849be02bf5a5a8879fcb641 (patch) | |
tree | d1e6c76a8427988a62a36ce17dac0d74cec13627 | |
parent | 658d2f98437815782691571f373b42321ffc9226 (diff) |
disallow empty value strings when setting numbers in CCTK_ParameterSet
Before this patch due to the way strtol and strtod work one can do
CCTK_ParameterSet("cctk_itlast", "Cactus", "")
which returns 0 (all is fine) and sets cctk_itlast to 0 (rather than failing
with -6 "invalid string").
This cannot happen from inside of parfiles since the parser disallows it. It
can happen when using the Trigger thorn.
git-svn-id: http://svn.cactuscode.org/flesh/trunk@5083 17b73243-c579-4c4c-a9d2-2d5706c11dac
-rw-r--r-- | src/main/Parameters.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/main/Parameters.c b/src/main/Parameters.c index 443ab6ec..428c405f 100644 --- a/src/main/Parameters.c +++ b/src/main/Parameters.c @@ -2206,9 +2206,12 @@ static int ParameterSetInteger (t_param *param, const char *value) retval = 0; /* try parsing as number */ - inval = strtol (value, &endptr, 0); + if (strcmp(value, "") == 0) /* strtol returns 0 in this case */ + retval = -6; + else + inval = strtol (value, &endptr, 0); - if (*endptr) /* if we could not parse as a number, try an expression */ + if (!retval && *endptr) /* if we cannot parse as a number, try expression */ { int type = PARAMETER_INT; uExpressionValue val; @@ -2315,9 +2318,12 @@ static int ParameterSetReal (t_param *param, const char *value) } /* try parsing as number */ - inval = strtod (temp, &endptr); + if (strcmp(value, "") == 0) /* strtod returns 0. in this case */ + retval = -6; + else + inval = strtod (temp, &endptr); - if (*endptr) /* if we cannot parse as a number, try expression */ + if (!retval && *endptr) /* if we cannot parse as a number, try expression */ { int type = PARAMETER_REAL; uExpressionValue val; |