From 1558c5abcb086f73d0065cb5012820997732827f Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Thu, 13 Jan 2022 14:48:35 +0100 Subject: [PATCH] Add a suitable error message and fallback to default temperature if an error in the temperature entry is found. --- src/frontend/inp.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/frontend/inp.c b/src/frontend/inp.c index b4fa0ed14..176b97bc7 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -1023,9 +1023,17 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) /* set temperature, if defined, to new value. cp_vset will set the variable "temp" and also set CKTtemp, - so we can do it only here because the circuit has to be already there */ + so we can do it only here because the circuit has to be already existing */ if (temperature) { - temperature_value = atof(temperature); + char *endstr; + temperature_value = strtod(temperature, &endstr); + /* number strngs from numparam may contain trailing spaces */ + endstr = skip_ws(endstr); + /* if endstr contains characters, temperature has not been a pure number string */ + if (*endstr != '\0') { + fprintf(stderr, "Warning: Could not set temperature to %s\n Set to default 27 C instead.\n", temperature); + temperature_value = 27; + } cp_vset("temp", CP_REAL, &temperature_value); txfree(temperature); }