mirror of
https://github.com/postgres/postgres.git
synced 2025-06-23 14:01:44 +03:00
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.
This commit is contained in:
@ -723,9 +723,13 @@ int4div(PG_FUNCTION_ARGS)
|
|||||||
int32 result;
|
int32 result;
|
||||||
|
|
||||||
if (arg2 == 0)
|
if (arg2 == 0)
|
||||||
|
{
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_DIVISION_BY_ZERO),
|
(errcode(ERRCODE_DIVISION_BY_ZERO),
|
||||||
errmsg("division by zero")));
|
errmsg("division by zero")));
|
||||||
|
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
|
||||||
|
PG_RETURN_NULL();
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
||||||
@ -864,9 +868,13 @@ int2div(PG_FUNCTION_ARGS)
|
|||||||
int16 result;
|
int16 result;
|
||||||
|
|
||||||
if (arg2 == 0)
|
if (arg2 == 0)
|
||||||
|
{
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_DIVISION_BY_ZERO),
|
(errcode(ERRCODE_DIVISION_BY_ZERO),
|
||||||
errmsg("division by zero")));
|
errmsg("division by zero")));
|
||||||
|
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
|
||||||
|
PG_RETURN_NULL();
|
||||||
|
}
|
||||||
|
|
||||||
result = arg1 / arg2;
|
result = arg1 / arg2;
|
||||||
|
|
||||||
@ -1048,9 +1056,13 @@ int42div(PG_FUNCTION_ARGS)
|
|||||||
int32 result;
|
int32 result;
|
||||||
|
|
||||||
if (arg2 == 0)
|
if (arg2 == 0)
|
||||||
|
{
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_DIVISION_BY_ZERO),
|
(errcode(ERRCODE_DIVISION_BY_ZERO),
|
||||||
errmsg("division by zero")));
|
errmsg("division by zero")));
|
||||||
|
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
|
||||||
|
PG_RETURN_NULL();
|
||||||
|
}
|
||||||
|
|
||||||
result = arg1 / arg2;
|
result = arg1 / arg2;
|
||||||
|
|
||||||
@ -1074,9 +1086,13 @@ int4mod(PG_FUNCTION_ARGS)
|
|||||||
int32 arg2 = PG_GETARG_INT32(1);
|
int32 arg2 = PG_GETARG_INT32(1);
|
||||||
|
|
||||||
if (arg2 == 0)
|
if (arg2 == 0)
|
||||||
|
{
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_DIVISION_BY_ZERO),
|
(errcode(ERRCODE_DIVISION_BY_ZERO),
|
||||||
errmsg("division by zero")));
|
errmsg("division by zero")));
|
||||||
|
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
|
||||||
|
PG_RETURN_NULL();
|
||||||
|
}
|
||||||
|
|
||||||
/* SELECT ((-2147483648)::int4) % (-1); causes a floating point exception */
|
/* SELECT ((-2147483648)::int4) % (-1); causes a floating point exception */
|
||||||
if (arg1 == INT_MIN && arg2 == -1)
|
if (arg1 == INT_MIN && arg2 == -1)
|
||||||
@ -1094,9 +1110,14 @@ int2mod(PG_FUNCTION_ARGS)
|
|||||||
int16 arg2 = PG_GETARG_INT16(1);
|
int16 arg2 = PG_GETARG_INT16(1);
|
||||||
|
|
||||||
if (arg2 == 0)
|
if (arg2 == 0)
|
||||||
|
{
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_DIVISION_BY_ZERO),
|
(errcode(ERRCODE_DIVISION_BY_ZERO),
|
||||||
errmsg("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 */
|
/* No overflow is possible */
|
||||||
|
|
||||||
PG_RETURN_INT16(arg1 % arg2);
|
PG_RETURN_INT16(arg1 % arg2);
|
||||||
|
Reference in New Issue
Block a user