[PATCH 2/2] Clean up INT_MIN % -1 overflow in int4mod(). - Mailing list pgsql-hackers

From Xi Wang
Subject [PATCH 2/2] Clean up INT_MIN % -1 overflow in int4mod().
Date
Msg-id 50A41620.5040606@gmail.com
Whole thread Raw
In response to Re: [PATCH] Fix INT_MIN % -1 overflow in int8mod().  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Since x % -1 returns 0 for any x, we don't need the check x == INT_MIN.

Suggested by Tom Lane.
---src/backend/utils/adt/int.c |    2 +-1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/backend/utils/adt/int.c b/src/backend/utils/adt/int.c
index 4be3901..3e423fe 100644
--- a/src/backend/utils/adt/int.c
+++ b/src/backend/utils/adt/int.c
@@ -1096,7 +1096,7 @@ int4mod(PG_FUNCTION_ARGS)    }    /* SELECT ((-2147483648)::int4) % (-1); causes a floating point
exception*/
 
-    if (arg1 == INT_MIN && arg2 == -1)
+    if (arg2 == -1)        PG_RETURN_INT32(0);    /* No overflow is possible */
-- 
1.7.10.4




pgsql-hackers by date:

Previous
From: Xi Wang
Date:
Subject: [PATCH 1/2] Fix INT_MIN % -1 overflow in int8mod().
Next
From: Xi Wang
Date:
Subject: Re: [PATCH] Fix INT_MIN % -1 overflow in int8mod().