aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-09-03 18:48:14 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-09-03 18:48:14 +0000
commitd0a368c65699b32212575bb573474c18c29ddef9 (patch)
tree8e3614ae42acdba34aca5d719ef4f4fd4a0885c4
parentfc19373993f69bcc26a3910374c4b8689966212d (diff)
downloadpostgresql-d0a368c65699b32212575bb573474c18c29ddef9.tar.gz
postgresql-d0a368c65699b32212575bb573474c18c29ddef9.zip
Install a workaround for a longstanding gcc bug that allows SIGFPE traps
to occur for division by zero, even though the code is carefully avoiding that. All available evidence is that the only functions affected are int24div, int48div, and int28div, so patch just those three functions to include a "return" after the ereport() call. Backpatch to 8.4 so that the fix can be tested in production builds. For older branches our recommendation will continue to be to use -O1 on affected platforms (which are mostly non-mainstream anyway).
-rw-r--r--src/backend/utils/adt/int.c7
-rw-r--r--src/backend/utils/adt/int8.c12
2 files changed, 17 insertions, 2 deletions
diff --git a/src/backend/utils/adt/int.c b/src/backend/utils/adt/int.c
index 5214e29825c..ad4df06572f 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.84 2009/01/01 17:23:49 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/int.c,v 1.85 2009/09/03 18:48:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -950,9 +950,14 @@ int24div(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();
+ }
+
/* No overflow is possible */
PG_RETURN_INT32((int32) arg1 / arg2);
}
diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c
index 89162f080ec..54a134d4778 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.74 2009/06/11 14:49:03 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/int8.c,v 1.75 2009/09/03 18:48:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -919,9 +919,14 @@ int48div(PG_FUNCTION_ARGS)
int64 arg2 = PG_GETARG_INT64(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_INT64((int64) arg1 / arg2);
}
@@ -1098,9 +1103,14 @@ int28div(PG_FUNCTION_ARGS)
int64 arg2 = PG_GETARG_INT64(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_INT64((int64) arg1 / arg2);
}