Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7233099

Browse files
committed
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 haveenabled it to break functions that weren't broken before.Aurelien Jarno, via Martin Pitt
1 parent8acdb8b commit7233099

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎src/backend/utils/adt/int8.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,13 @@ int8div(PG_FUNCTION_ARGS)
590590
int64result;
591591

592592
if (arg2==0)
593+
{
593594
ereport(ERROR,
594595
(errcode(ERRCODE_DIVISION_BY_ZERO),
595596
errmsg("division by zero")));
597+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
598+
PG_RETURN_NULL();
599+
}
596600

597601
result=arg1 /arg2;
598602

@@ -637,9 +641,14 @@ int8mod(PG_FUNCTION_ARGS)
637641
int64arg2=PG_GETARG_INT64(1);
638642

639643
if (arg2==0)
644+
{
640645
ereport(ERROR,
641646
(errcode(ERRCODE_DIVISION_BY_ZERO),
642647
errmsg("division by zero")));
648+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
649+
PG_RETURN_NULL();
650+
}
651+
643652
/* No overflow is possible */
644653

645654
PG_RETURN_INT64(arg1 %arg2);
@@ -813,9 +822,13 @@ int84div(PG_FUNCTION_ARGS)
813822
int64result;
814823

815824
if (arg2==0)
825+
{
816826
ereport(ERROR,
817827
(errcode(ERRCODE_DIVISION_BY_ZERO),
818828
errmsg("division by zero")));
829+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
830+
PG_RETURN_NULL();
831+
}
819832

820833
result=arg1 /arg2;
821834

@@ -997,9 +1010,13 @@ int82div(PG_FUNCTION_ARGS)
9971010
int64result;
9981011

9991012
if (arg2==0)
1013+
{
10001014
ereport(ERROR,
10011015
(errcode(ERRCODE_DIVISION_BY_ZERO),
10021016
errmsg("division by zero")));
1017+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
1018+
PG_RETURN_NULL();
1019+
}
10031020

10041021
result=arg1 /arg2;
10051022

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp