Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eeaef25

Browse files
committed
Fix some portability issues with new float input code (didn't work on
HPUX 11 ...)
1 parent 47fe051 commit eeaef25

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/backend/utils/adt/float.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.102 2004/04/01 22:51:31 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.103 2004/04/01 23:52:18 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -282,19 +282,14 @@ float4in(PG_FUNCTION_ARGS)
282282
errno = 0;
283283
val = strtod(num, &endptr);
284284

285-
if (errno == ERANGE)
286-
ereport(ERROR,
287-
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
288-
errmsg("\"%s\" is out of range for type real",
289-
orig_num)));
290-
291285
/* did we not see anything that looks like a double? */
292-
if (num == endptr)
286+
if (endptr == num || errno != 0)
293287
{
294288
/*
295289
* C99 requires that strtod() accept NaN and [-]Infinity, but
296-
* not all platforms support that yet. Therefore, we check for
297-
* these inputs ourselves.
290+
* not all platforms support that yet (and some accept them but
291+
* set ERANGE anyway...) Therefore, we check for these inputs
292+
* ourselves.
298293
*/
299294
if (strncasecmp(num, "NaN", 3) == 0)
300295
{
@@ -311,6 +306,11 @@ float4in(PG_FUNCTION_ARGS)
311306
val = - get_float4_infinity();
312307
endptr = num + 9;
313308
}
309+
else if (errno == ERANGE)
310+
ereport(ERROR,
311+
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
312+
errmsg("\"%s\" is out of range for type real",
313+
orig_num)));
314314
else
315315
ereport(ERROR,
316316
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
@@ -447,19 +447,14 @@ float8in(PG_FUNCTION_ARGS)
447447
errno = 0;
448448
val = strtod(num, &endptr);
449449

450-
if (errno == ERANGE)
451-
ereport(ERROR,
452-
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
453-
errmsg("\"%s\" is out of range for type double precision",
454-
orig_num)));
455-
456450
/* did we not see anything that looks like a double? */
457-
if (num == endptr)
451+
if (endptr == num || errno != 0)
458452
{
459453
/*
460454
* C99 requires that strtod() accept NaN and [-]Infinity, but
461-
* not all platforms support that yet. Therefore, we check for
462-
* these inputs ourselves.
455+
* not all platforms support that yet (and some accept them but
456+
* set ERANGE anyway...) Therefore, we check for these inputs
457+
* ourselves.
463458
*/
464459
if (strncasecmp(num, "NaN", 3) == 0)
465460
{
@@ -476,6 +471,11 @@ float8in(PG_FUNCTION_ARGS)
476471
val = - get_float8_infinity();
477472
endptr = num + 9;
478473
}
474+
else if (errno == ERANGE)
475+
ereport(ERROR,
476+
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
477+
errmsg("\"%s\" is out of range for type double precision",
478+
orig_num)));
479479
else
480480
ereport(ERROR,
481481
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),

0 commit comments

Comments
 (0)