aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/int8.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-03-11 18:18:55 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2011-03-11 18:18:55 -0500
commit72330995a52fb7a3fbdc666aebc0402cdcbc9af8 (patch)
tree0740200b06914a2170c0286d5075e52bd90aa781 /src/backend/utils/adt/int8.c
parent8acdb8bf9cebc42cee5aa96a2d594756b44173c9 (diff)
downloadpostgresql-72330995a52fb7a3fbdc666aebc0402cdcbc9af8.tar.gz
postgresql-72330995a52fb7a3fbdc666aebc0402cdcbc9af8.zip
Put in some more safeguards against executing a division-by-zero.
Add dummy returns before every potential division-by-zero in int8.c, because apparently further "improvements" in gcc's optimizer have enabled it to break functions that weren't broken before. Aurelien Jarno, via Martin Pitt
Diffstat (limited to 'src/backend/utils/adt/int8.c')
-rw-r--r--src/backend/utils/adt/int8.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c
index bbab90c0c13..451916480cd 100644
--- a/src/backend/utils/adt/int8.c
+++ b/src/backend/utils/adt/int8.c
@@ -590,9 +590,13 @@ int8div(PG_FUNCTION_ARGS)
int64 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;
@@ -637,9 +641,14 @@ int8mod(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(arg1 % arg2);
@@ -813,9 +822,13 @@ int84div(PG_FUNCTION_ARGS)
int64 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;
@@ -997,9 +1010,13 @@ int82div(PG_FUNCTION_ARGS)
int64 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;