diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-03-11 19:04:18 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-03-11 19:04:18 -0500 |
commit | 1b5a7779cbe37a750f799b6314ceb43b8a0e5aba (patch) | |
tree | 33a99a8771d39d5da8b8c67e415f65f6fe739012 /src | |
parent | a396d881186600e7f537dba42100996a2590a580 (diff) | |
download | postgresql-1b5a7779cbe37a750f799b6314ceb43b8a0e5aba.tar.gz postgresql-1b5a7779cbe37a750f799b6314ceb43b8a0e5aba.zip |
On further reflection, we'd better do the same in int.c.
We previously heard of the same problem in int24div(), so there's not a
good reason to suppose the problem is confined to cases involving int8.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/utils/adt/int.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/backend/utils/adt/int.c b/src/backend/utils/adt/int.c index 3970bda83d2..47a0bd2a801 100644 --- a/src/backend/utils/adt/int.c +++ b/src/backend/utils/adt/int.c @@ -778,9 +778,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 @@ -918,9 +922,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; @@ -1012,10 +1020,16 @@ 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); } @@ -1096,9 +1110,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; @@ -1121,9 +1139,14 @@ 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(); + } + /* No overflow is possible */ PG_RETURN_INT32(arg1 % arg2); @@ -1136,9 +1159,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); @@ -1151,9 +1179,14 @@ int24mod(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(arg1 % arg2); @@ -1166,9 +1199,14 @@ int42mod(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_INT32(arg1 % arg2); |