提交 72330995 编写于 作者: T Tom Lane

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
上级 8acdb8bf
......@@ -590,9 +590,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;
......@@ -637,9 +641,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);
......@@ -813,9 +822,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;
......@@ -997,9 +1010,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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册