diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-03-11 18:19:07 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-03-11 18:19:07 -0500 |
commit | 24aad03e98a7e38614100457defdedf75c473bc4 (patch) | |
tree | 95c1d54f13ce174c6c95e6de32a7722b4eab9030 /src | |
parent | e476eedd0c06e81ee6d76fd8dc23eb5d54f1ba0b (diff) |
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')
-rw-r--r-- | src/backend/utils/adt/int8.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c index 3391769cd43..88bf703df67 100644 --- a/src/backend/utils/adt/int8.c +++ b/src/backend/utils/adt/int8.c @@ -599,9 +599,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; @@ -645,9 +649,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); @@ -821,9 +830,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; @@ -915,10 +928,16 @@ 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); } |