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

From: Xi Wang <xi(dot)wang(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: [PATCH 2/2] Clean up INT_MIN % -1 overflow in int4mod().
Date: 2012-11-14 22:07:28
Message-ID: 50A41620.5040606@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Xi Wang 2012-11-14 22:08:52 Re: [PATCH] Fix INT_MIN % -1 overflow in int8mod().
Previous Message Xi Wang 2012-11-14 22:05:28 [PATCH 1/2] Fix INT_MIN % -1 overflow in int8mod().