1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-22 23:02:54 +03:00

Improper addition of NaN/Infinity recognition to float8in()

was causing it not to detect out-of-range float values, as evidenced by
failure of float8 regression test.  I corrected that logic and also
modified expected float8 results to account for new error message
generated for out-of-range inputs.
This commit is contained in:
Tom Lane 1999-01-24 00:12:59 +00:00
parent 598a4e15dd
commit 157349e3af
2 changed files with 20 additions and 8 deletions

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.38 1999/01/21 16:08:51 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.39 1999/01/24 00:12:59 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -209,8 +209,16 @@ float4in(char *num)
errno = 0; errno = 0;
val = strtod(num, &endptr); val = strtod(num, &endptr);
if (*endptr != '\0' || errno == ERANGE) if (*endptr != '\0')
{
/* Should we accept "NaN" or "Infinity" for float4? */
elog(ERROR, "Bad float4 input format '%s'", num); elog(ERROR, "Bad float4 input format '%s'", num);
}
else
{
if (errno == ERANGE)
elog(ERROR, "Input '%s' is out of range for float4", num);
}
/* /*
* if we get here, we have a legal double, still need to check to see * if we get here, we have a legal double, still need to check to see
@ -262,13 +270,17 @@ float8in(char *num)
val = NAN; val = NAN;
else if (strcasecmp(num, "Infinity") == 0) else if (strcasecmp(num, "Infinity") == 0)
val = HUGE_VAL; val = HUGE_VAL;
else if (errno == ERANGE)
elog(ERROR, "Input '%s' is out of range for float8", num);
else else
elog(ERROR, "Bad float8 input format '%s'", num); elog(ERROR, "Bad float8 input format '%s'", num);
} }
else
{
if (errno == ERANGE)
elog(ERROR, "Input '%s' is out of range for float8", num);
}
CheckFloat8Val(val); CheckFloat8Val(val);
*result = val; *result = val;
return result; return result;
} }

View File

@ -209,13 +209,13 @@ five|f1
(5 rows) (5 rows)
QUERY: INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400'); QUERY: INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');
ERROR: Bad float8 input format '10e400' ERROR: Input '10e400' is out of range for float8
QUERY: INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400'); QUERY: INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400');
ERROR: Bad float8 input format '-10e400' ERROR: Input '-10e400' is out of range for float8
QUERY: INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400'); QUERY: INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400');
ERROR: Bad float8 input format '10e-400' ERROR: Input '10e-400' is out of range for float8
QUERY: INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400'); QUERY: INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400');
ERROR: Bad float8 input format '-10e-400' ERROR: Input '-10e-400' is out of range for float8
QUERY: DELETE FROM FLOAT8_TBL; QUERY: DELETE FROM FLOAT8_TBL;
QUERY: INSERT INTO FLOAT8_TBL(f1) VALUES ('0.0'); QUERY: INSERT INTO FLOAT8_TBL(f1) VALUES ('0.0');
QUERY: INSERT INTO FLOAT8_TBL(f1) VALUES ('-34.84'); QUERY: INSERT INTO FLOAT8_TBL(f1) VALUES ('-34.84');