aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/int.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2007-01-02 20:00:50 +0000
committerBruce Momjian <bruce@momjian.us>2007-01-02 20:00:50 +0000
commitf9ac414c35ea084ff70c564ab2c32adb06d5296f (patch)
treecec15aa55c29cbf431576e87ba2e950e0226549b /src/backend/utils/adt/int.c
parent0b56be83441c01419fcf82ebe666e968e6f7b246 (diff)
downloadpostgresql-f9ac414c35ea084ff70c564ab2c32adb06d5296f.tar.gz
postgresql-f9ac414c35ea084ff70c564ab2c32adb06d5296f.zip
Fix float4/8 to handle Infinity and Nan consistently, e.g. Infinity is a
valid result from a computation if one of the input values was infinity. The previous code assumed an operation that returned infinity was an overflow. Handle underflow/overflow consistently, and add checks for aggregate overflow. Consistently prevent Inf/Nan from being cast to integer data types. Fix INT_MIN % -1 to prevent overflow. Update regression results for new error text. Per report from Roman Kononov.
Diffstat (limited to 'src/backend/utils/adt/int.c')
-rw-r--r--src/backend/utils/adt/int.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/backend/utils/adt/int.c b/src/backend/utils/adt/int.c
index 3970bda83d2..194b96c7208 100644
--- a/src/backend/utils/adt/int.c
+++ b/src/backend/utils/adt/int.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/int.c,v 1.75 2006/10/04 00:29:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/int.c,v 1.76 2007/01/02 20:00:49 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1124,6 +1124,11 @@ int4mod(PG_FUNCTION_ARGS)
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
+
+ /* SELECT ((-2147483648)::int4) % (-1); causes a floating point exception */
+ if (arg1 == INT_MIN && arg2 == -1)
+ PG_RETURN_INT32(0);
+
/* No overflow is possible */
PG_RETURN_INT32(arg1 % arg2);