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

Commita396d88

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 parent1487ca0 commita396d88

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,13 @@ int8div(PG_FUNCTION_ARGS)
595595
int64result;
596596

597597
if (arg2==0)
598+
{
598599
ereport(ERROR,
599600
(errcode(ERRCODE_DIVISION_BY_ZERO),
600601
errmsg("division by zero")));
602+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
603+
PG_RETURN_NULL();
604+
}
601605

602606
result=arg1 /arg2;
603607

@@ -641,9 +645,14 @@ int8mod(PG_FUNCTION_ARGS)
641645
int64arg2=PG_GETARG_INT64(1);
642646

643647
if (arg2==0)
648+
{
644649
ereport(ERROR,
645650
(errcode(ERRCODE_DIVISION_BY_ZERO),
646651
errmsg("division by zero")));
652+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
653+
PG_RETURN_NULL();
654+
}
655+
647656
/* No overflow is possible */
648657

649658
PG_RETURN_INT64(arg1 %arg2);
@@ -817,9 +826,13 @@ int84div(PG_FUNCTION_ARGS)
817826
int64result;
818827

819828
if (arg2==0)
829+
{
820830
ereport(ERROR,
821831
(errcode(ERRCODE_DIVISION_BY_ZERO),
822832
errmsg("division by zero")));
833+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
834+
PG_RETURN_NULL();
835+
}
823836

824837
result=arg1 /arg2;
825838

@@ -911,10 +924,16 @@ int48div(PG_FUNCTION_ARGS)
911924
int64arg2=PG_GETARG_INT64(1);
912925

913926
if (arg2==0)
927+
{
914928
ereport(ERROR,
915929
(errcode(ERRCODE_DIVISION_BY_ZERO),
916930
errmsg("division by zero")));
931+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
932+
PG_RETURN_NULL();
933+
}
934+
917935
/* No overflow is possible */
936+
918937
PG_RETURN_INT64((int64)arg1 /arg2);
919938
}
920939

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp