|
7 | 7 | * Portions Copyright (c) 1994, Regents of the University of California
|
8 | 8 | *
|
9 | 9 | * IDENTIFICATION
|
10 |
| - * $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.32 2001/08/24 14:07:49 petere Exp $ |
| 10 | + * $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.33 2001/09/07 01:33:44 tgl Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -67,7 +67,7 @@ int8in(PG_FUNCTION_ARGS)
|
67 | 67 | * Do our own scan, rather than relying on sscanf which might be
|
68 | 68 | * broken for long long.
|
69 | 69 | */
|
70 |
| -while (*ptr&&isspace((unsignedchar)*ptr))/* skip leading spaces */ |
| 70 | +while (*ptr&&isspace((unsignedchar)*ptr))/* skip leading spaces */ |
71 | 71 | ptr++;
|
72 | 72 | if (*ptr=='-')/* handle sign */
|
73 | 73 | sign=-1,ptr++;
|
@@ -688,11 +688,12 @@ int84(PG_FUNCTION_ARGS)
|
688 | 688 | int64val=PG_GETARG_INT64(0);
|
689 | 689 | int32result;
|
690 | 690 |
|
691 |
| -if ((val<INT_MIN)|| (val>INT_MAX)) |
692 |
| -elog(ERROR,"int8 conversion to int4 is out of range"); |
693 |
| - |
694 | 691 | result= (int32)val;
|
695 | 692 |
|
| 693 | +/* Test for overflow by reverse-conversion. */ |
| 694 | +if ((int64)result!=val) |
| 695 | +elog(ERROR,"int8 conversion to int4 is out of range"); |
| 696 | + |
696 | 697 | PG_RETURN_INT32(result);
|
697 | 698 | }
|
698 | 699 |
|
|