From 157349e3afdb5282cc177e53f4c435ab343b113f Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Sun, 24 Jan 1999 00:12:59 +0000
Subject: [PATCH] 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.

---
 src/backend/utils/adt/float.c        | 20 ++++++++++++++++----
 src/test/regress/expected/float8.out |  8 ++++----
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c
index a700a52d33d..c9f4b0ee200 100644
--- a/src/backend/utils/adt/float.c
+++ b/src/backend/utils/adt/float.c
@@ -7,7 +7,7 @@
  *
  *
  * 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;
 	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);
+	}
+	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
@@ -262,13 +270,17 @@ float8in(char *num)
 			val = NAN;
 		else if (strcasecmp(num, "Infinity") == 0)
 			val = HUGE_VAL;
-		else if (errno == ERANGE)
-			elog(ERROR, "Input '%s' is out of range for float8", num);
 		else
 			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);
+
 	*result = val;
 	return result;
 }
diff --git a/src/test/regress/expected/float8.out b/src/test/regress/expected/float8.out
index 6434d8eb261..90f7bc37c8a 100644
--- a/src/test/regress/expected/float8.out
+++ b/src/test/regress/expected/float8.out
@@ -209,13 +209,13 @@ five|f1
 (5 rows)
 
 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');
-ERROR:  Bad float8 input format '-10e400'
+ERROR:  Input '-10e400' is out of range for float8
 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');
-ERROR:  Bad float8 input format '-10e-400'
+ERROR:  Input '-10e-400' is out of range for float8
 QUERY: DELETE FROM FLOAT8_TBL;
 QUERY: INSERT INTO FLOAT8_TBL(f1) VALUES ('0.0');
 QUERY: INSERT INTO FLOAT8_TBL(f1) VALUES ('-34.84');
-- 
GitLab