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

Commit1b5a777

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 parenta396d88 commit1b5a777

File tree

1 file changed

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

1 file changed

+38
-0
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,9 +778,13 @@ int4div(PG_FUNCTION_ARGS)
778778
int32result;
779779

780780
if (arg2==0)
781+
{
781782
ereport(ERROR,
782783
(errcode(ERRCODE_DIVISION_BY_ZERO),
783784
errmsg("division by zero")));
785+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
786+
PG_RETURN_NULL();
787+
}
784788

785789
#ifdefWIN32
786790

@@ -918,9 +922,13 @@ int2div(PG_FUNCTION_ARGS)
918922
int16result;
919923

920924
if (arg2==0)
925+
{
921926
ereport(ERROR,
922927
(errcode(ERRCODE_DIVISION_BY_ZERO),
923928
errmsg("division by zero")));
929+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
930+
PG_RETURN_NULL();
931+
}
924932

925933
result=arg1 /arg2;
926934

@@ -1012,10 +1020,16 @@ int24div(PG_FUNCTION_ARGS)
10121020
int32arg2=PG_GETARG_INT32(1);
10131021

10141022
if (arg2==0)
1023+
{
10151024
ereport(ERROR,
10161025
(errcode(ERRCODE_DIVISION_BY_ZERO),
10171026
errmsg("division by zero")));
1027+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
1028+
PG_RETURN_NULL();
1029+
}
1030+
10181031
/* No overflow is possible */
1032+
10191033
PG_RETURN_INT32((int32)arg1 /arg2);
10201034
}
10211035

@@ -1096,9 +1110,13 @@ int42div(PG_FUNCTION_ARGS)
10961110
int32result;
10971111

10981112
if (arg2==0)
1113+
{
10991114
ereport(ERROR,
11001115
(errcode(ERRCODE_DIVISION_BY_ZERO),
11011116
errmsg("division by zero")));
1117+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
1118+
PG_RETURN_NULL();
1119+
}
11021120

11031121
result=arg1 /arg2;
11041122

@@ -1121,9 +1139,14 @@ int4mod(PG_FUNCTION_ARGS)
11211139
int32arg2=PG_GETARG_INT32(1);
11221140

11231141
if (arg2==0)
1142+
{
11241143
ereport(ERROR,
11251144
(errcode(ERRCODE_DIVISION_BY_ZERO),
11261145
errmsg("division by zero")));
1146+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
1147+
PG_RETURN_NULL();
1148+
}
1149+
11271150
/* No overflow is possible */
11281151

11291152
PG_RETURN_INT32(arg1 %arg2);
@@ -1136,9 +1159,14 @@ int2mod(PG_FUNCTION_ARGS)
11361159
int16arg2=PG_GETARG_INT16(1);
11371160

11381161
if (arg2==0)
1162+
{
11391163
ereport(ERROR,
11401164
(errcode(ERRCODE_DIVISION_BY_ZERO),
11411165
errmsg("division by zero")));
1166+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
1167+
PG_RETURN_NULL();
1168+
}
1169+
11421170
/* No overflow is possible */
11431171

11441172
PG_RETURN_INT16(arg1 %arg2);
@@ -1151,9 +1179,14 @@ int24mod(PG_FUNCTION_ARGS)
11511179
int32arg2=PG_GETARG_INT32(1);
11521180

11531181
if (arg2==0)
1182+
{
11541183
ereport(ERROR,
11551184
(errcode(ERRCODE_DIVISION_BY_ZERO),
11561185
errmsg("division by zero")));
1186+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
1187+
PG_RETURN_NULL();
1188+
}
1189+
11571190
/* No overflow is possible */
11581191

11591192
PG_RETURN_INT32(arg1 %arg2);
@@ -1166,9 +1199,14 @@ int42mod(PG_FUNCTION_ARGS)
11661199
int16arg2=PG_GETARG_INT16(1);
11671200

11681201
if (arg2==0)
1202+
{
11691203
ereport(ERROR,
11701204
(errcode(ERRCODE_DIVISION_BY_ZERO),
11711205
errmsg("division by zero")));
1206+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
1207+
PG_RETURN_NULL();
1208+
}
1209+
11721210
/* No overflow is possible */
11731211

11741212
PG_RETURN_INT32(arg1 %arg2);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp