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

Commit2a26639

Browse files
committed
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 agood reason to suppose the problem is confined to cases involving int8.
1 parent7233099 commit2a26639

File tree

1 file changed

+21
-0
lines changed
  • src/backend/utils/adt

1 file changed

+21
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,9 +723,13 @@ int4div(PG_FUNCTION_ARGS)
723723
int32result;
724724

725725
if (arg2==0)
726+
{
726727
ereport(ERROR,
727728
(errcode(ERRCODE_DIVISION_BY_ZERO),
728729
errmsg("division by zero")));
730+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
731+
PG_RETURN_NULL();
732+
}
729733

730734
#ifdefWIN32
731735

@@ -864,9 +868,13 @@ int2div(PG_FUNCTION_ARGS)
864868
int16result;
865869

866870
if (arg2==0)
871+
{
867872
ereport(ERROR,
868873
(errcode(ERRCODE_DIVISION_BY_ZERO),
869874
errmsg("division by zero")));
875+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
876+
PG_RETURN_NULL();
877+
}
870878

871879
result=arg1 /arg2;
872880

@@ -1048,9 +1056,13 @@ int42div(PG_FUNCTION_ARGS)
10481056
int32result;
10491057

10501058
if (arg2==0)
1059+
{
10511060
ereport(ERROR,
10521061
(errcode(ERRCODE_DIVISION_BY_ZERO),
10531062
errmsg("division by zero")));
1063+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
1064+
PG_RETURN_NULL();
1065+
}
10541066

10551067
result=arg1 /arg2;
10561068

@@ -1074,9 +1086,13 @@ int4mod(PG_FUNCTION_ARGS)
10741086
int32arg2=PG_GETARG_INT32(1);
10751087

10761088
if (arg2==0)
1089+
{
10771090
ereport(ERROR,
10781091
(errcode(ERRCODE_DIVISION_BY_ZERO),
10791092
errmsg("division by zero")));
1093+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
1094+
PG_RETURN_NULL();
1095+
}
10801096

10811097
/* SELECT ((-2147483648)::int4) % (-1); causes a floating point exception */
10821098
if (arg1==INT_MIN&&arg2==-1)
@@ -1094,9 +1110,14 @@ int2mod(PG_FUNCTION_ARGS)
10941110
int16arg2=PG_GETARG_INT16(1);
10951111

10961112
if (arg2==0)
1113+
{
10971114
ereport(ERROR,
10981115
(errcode(ERRCODE_DIVISION_BY_ZERO),
10991116
errmsg("division by zero")));
1117+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
1118+
PG_RETURN_NULL();
1119+
}
1120+
11001121
/* No overflow is possible */
11011122

11021123
PG_RETURN_INT16(arg1 %arg2);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp