From wajap at github:

- eat whitespace in infnan checks
- set fval to 0 if we are not a floating point number
This commit is contained in:
christos 2020-11-02 22:58:51 +00:00
parent 3ef5b1ede1
commit 358fc34e52

View File

@ -399,11 +399,15 @@ static int checkstr(const char *s, const char *v)
{
while (*s && tolower((unsigned char)*s) == *v)
s++, v++;
while (isspace((unsigned char)*s))
s++;
return !(*s || *v);
}
static int checkinfnan(const char *s)
{
while (isspace((unsigned char)*s))
s++;
if (*s == '+' || *s == '-')
s++;
switch (tolower((unsigned char)*s)) {
@ -427,6 +431,8 @@ Awkfloat getfval(Cell *vp) /* get float val of a Cell */
if (!isnum(vp)) { /* not a number */
if (checkinfnan(vp->sval))
vp->fval = atof(vp->sval); /* best guess */
else
vp->fval = 0.0;
if (is_number(vp->sval) && !(vp->tval&CON)) {
vp->tval |= NUM; /* make NUM only sparingly */
}