mirror of
https://github.com/postgres/postgres.git
synced 2025-05-11 05:41:32 +03:00
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
This commit is contained in:
parent
1487ca0514
commit
a396d88118
@ -595,9 +595,13 @@ int8div(PG_FUNCTION_ARGS)
|
|||||||
int64 result;
|
int64 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;
|
||||||
|
|
||||||
@ -641,9 +645,14 @@ int8mod(PG_FUNCTION_ARGS)
|
|||||||
int64 arg2 = PG_GETARG_INT64(1);
|
int64 arg2 = PG_GETARG_INT64(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_INT64(arg1 % arg2);
|
PG_RETURN_INT64(arg1 % arg2);
|
||||||
@ -817,9 +826,13 @@ int84div(PG_FUNCTION_ARGS)
|
|||||||
int64 result;
|
int64 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;
|
||||||
|
|
||||||
@ -911,10 +924,16 @@ int48div(PG_FUNCTION_ARGS)
|
|||||||
int64 arg2 = PG_GETARG_INT64(1);
|
int64 arg2 = PG_GETARG_INT64(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_INT64((int64) arg1 / arg2);
|
PG_RETURN_INT64((int64) arg1 / arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user