summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2001-09-07 01:33:44 +0000
committerTom Lane2001-09-07 01:33:44 +0000
commit0fc7779d2e0656c345227ac323af4d6a8af8aceb (patch)
tree2335622e4b0cb2978694f7660e21cc078b237bac
parentde77c555159b2dba94b1db99aad8c25ccfa84632 (diff)
Revise overflow test in int84() to avoid codegen bug in some older
versions of gcc. We don't really need to explicitly test the limits anyway, just reverse-convert and see if we get the same answer.
-rw-r--r--src/backend/utils/adt/int8.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c
index 7a93d219d70..8d8f9ed6420 100644
--- a/src/backend/utils/adt/int8.c
+++ b/src/backend/utils/adt/int8.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.32 2001/08/24 14:07:49 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.33 2001/09/07 01:33:44 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -67,7 +67,7 @@ int8in(PG_FUNCTION_ARGS)
* Do our own scan, rather than relying on sscanf which might be
* broken for long long.
*/
- while (*ptr && isspace((unsigned char) *ptr)) /* skip leading spaces */
+ while (*ptr && isspace((unsigned char) *ptr)) /* skip leading spaces */
ptr++;
if (*ptr == '-') /* handle sign */
sign = -1, ptr++;
@@ -688,11 +688,12 @@ int84(PG_FUNCTION_ARGS)
int64 val = PG_GETARG_INT64(0);
int32 result;
- if ((val < INT_MIN) || (val > INT_MAX))
- elog(ERROR, "int8 conversion to int4 is out of range");
-
result = (int32) val;
+ /* Test for overflow by reverse-conversion. */
+ if ((int64) result != val)
+ elog(ERROR, "int8 conversion to int4 is out of range");
+
PG_RETURN_INT32(result);
}