aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/utils/adt/int.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/backend/utils/adt/int.c b/src/backend/utils/adt/int.c
index d0841b81ea8..abe3c7eae03 100644
--- a/src/backend/utils/adt/int.c
+++ b/src/backend/utils/adt/int.c
@@ -714,9 +714,13 @@ int4div(PG_FUNCTION_ARGS)
int32 result;
if (arg2 == 0)
+ {
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
+ /* ensure compiler realizes we mustn't reach the division (gcc bug) */
+ PG_RETURN_NULL();
+ }
#ifdef WIN32
@@ -855,9 +859,13 @@ int2div(PG_FUNCTION_ARGS)
int16 result;
if (arg2 == 0)
+ {
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
+ /* ensure compiler realizes we mustn't reach the division (gcc bug) */
+ PG_RETURN_NULL();
+ }
result = arg1 / arg2;
@@ -1039,9 +1047,13 @@ int42div(PG_FUNCTION_ARGS)
int32 result;
if (arg2 == 0)
+ {
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
+ /* ensure compiler realizes we mustn't reach the division (gcc bug) */
+ PG_RETURN_NULL();
+ }
result = arg1 / arg2;
@@ -1065,9 +1077,13 @@ int4mod(PG_FUNCTION_ARGS)
int32 arg2 = PG_GETARG_INT32(1);
if (arg2 == 0)
+ {
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
+ /* ensure compiler realizes we mustn't reach the division (gcc bug) */
+ PG_RETURN_NULL();
+ }
/* SELECT ((-2147483648)::int4) % (-1); causes a floating point exception */
if (arg1 == INT_MIN && arg2 == -1)
@@ -1085,9 +1101,14 @@ int2mod(PG_FUNCTION_ARGS)
int16 arg2 = PG_GETARG_INT16(1);
if (arg2 == 0)
+ {
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
+ /* ensure compiler realizes we mustn't reach the division (gcc bug) */
+ PG_RETURN_NULL();
+ }
+
/* No overflow is possible */
PG_RETURN_INT16(arg1 % arg2);