diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-03-11 18:18:59 -0500 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-03-11 18:18:59 -0500 |
| commit | 03aab8262ae7b32f8fc6cd8933dce9604d7fc07e (patch) | |
| tree | eb64d08a08b9590ff5a23f1021491333381e746f | |
| parent | 2f418e8a174136507fb1f80214415b144e24850c (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
| -rw-r--r-- | src/backend/utils/adt/int8.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c index 78bd5fb2b87..cde9313fdf9 100644 --- a/src/backend/utils/adt/int8.c +++ b/src/backend/utils/adt/int8.c @@ -592,9 +592,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; @@ -639,9 +643,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); @@ -815,9 +824,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; @@ -999,9 +1012,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; |
