aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/int8.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-10-05 23:18:37 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-10-05 23:18:37 +0000
commit8acfc7594da036f50f8bb79b642fb67bd7a93486 (patch)
tree9f2b35b9ab8a53993c0dcd8ea1a57f575b0c6f31 /src/backend/utils/adt/int8.c
parent1e4b03847c95287a81d531ab2a249ad07081c767 (diff)
downloadpostgresql-8acfc7594da036f50f8bb79b642fb67bd7a93486.tar.gz
postgresql-8acfc7594da036f50f8bb79b642fb67bd7a93486.zip
Tweak the overflow checks in integer division functions to complain if the
machine produces zero (rather than the more usual minimum-possible-integer) for the only possible overflow case. This has been seen to occur for at least some word widths on some hardware, and it's cheap enough to check for everywhere. Per Peter's analysis of buildfarm reports. This could be back-patched, but in the absence of any gripes from the field I doubt it's worth the trouble.
Diffstat (limited to 'src/backend/utils/adt/int8.c')
-rw-r--r--src/backend/utils/adt/int8.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c
index dc56df4d186..550c06f5d07 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
- * $PostgreSQL: pgsql/src/backend/utils/adt/int8.c,v 1.70 2008/06/17 19:10:56 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/int8.c,v 1.71 2008/10/05 23:18:37 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -608,9 +608,10 @@ int8div(PG_FUNCTION_ARGS)
/*
* Overflow check. The only possible overflow case is for arg1 =
* INT64_MIN, arg2 = -1, where the correct result is -INT64_MIN, which
- * can't be represented on a two's-complement machine.
+ * can't be represented on a two's-complement machine. Most machines
+ * produce INT64_MIN but it seems some produce zero.
*/
- if (arg2 == -1 && arg1 < 0 && result < 0)
+ if (arg2 == -1 && arg1 < 0 && result <= 0)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
@@ -830,9 +831,10 @@ int84div(PG_FUNCTION_ARGS)
/*
* Overflow check. The only possible overflow case is for arg1 =
* INT64_MIN, arg2 = -1, where the correct result is -INT64_MIN, which
- * can't be represented on a two's-complement machine.
+ * can't be represented on a two's-complement machine. Most machines
+ * produce INT64_MIN but it seems some produce zero.
*/
- if (arg2 == -1 && arg1 < 0 && result < 0)
+ if (arg2 == -1 && arg1 < 0 && result <= 0)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
@@ -1008,9 +1010,10 @@ int82div(PG_FUNCTION_ARGS)
/*
* Overflow check. The only possible overflow case is for arg1 =
* INT64_MIN, arg2 = -1, where the correct result is -INT64_MIN, which
- * can't be represented on a two's-complement machine.
+ * can't be represented on a two's-complement machine. Most machines
+ * produce INT64_MIN but it seems some produce zero.
*/
- if (arg2 == -1 && arg1 < 0 && result < 0)
+ if (arg2 == -1 && arg1 < 0 && result <= 0)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));