@@ -778,9 +778,13 @@ int4div(PG_FUNCTION_ARGS)
778
778
int32 result ;
779
779
780
780
if (arg2 == 0 )
781
+ {
781
782
ereport (ERROR ,
782
783
(errcode (ERRCODE_DIVISION_BY_ZERO ),
783
784
errmsg ("division by zero" )));
785
+ /* ensure compiler realizes we mustn't reach the division (gcc bug) */
786
+ PG_RETURN_NULL ();
787
+ }
784
788
785
789
#ifdef WIN32
786
790
@@ -918,9 +922,13 @@ int2div(PG_FUNCTION_ARGS)
918
922
int16 result ;
919
923
920
924
if (arg2 == 0 )
925
+ {
921
926
ereport (ERROR ,
922
927
(errcode (ERRCODE_DIVISION_BY_ZERO ),
923
928
errmsg ("division by zero" )));
929
+ /* ensure compiler realizes we mustn't reach the division (gcc bug) */
930
+ PG_RETURN_NULL ();
931
+ }
924
932
925
933
result = arg1 /arg2 ;
926
934
@@ -1012,10 +1020,16 @@ int24div(PG_FUNCTION_ARGS)
1012
1020
int32 arg2 = PG_GETARG_INT32 (1 );
1013
1021
1014
1022
if (arg2 == 0 )
1023
+ {
1015
1024
ereport (ERROR ,
1016
1025
(errcode (ERRCODE_DIVISION_BY_ZERO ),
1017
1026
errmsg ("division by zero" )));
1027
+ /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1028
+ PG_RETURN_NULL ();
1029
+ }
1030
+
1018
1031
/* No overflow is possible */
1032
+
1019
1033
PG_RETURN_INT32 ((int32 )arg1 /arg2 );
1020
1034
}
1021
1035
@@ -1096,9 +1110,13 @@ int42div(PG_FUNCTION_ARGS)
1096
1110
int32 result ;
1097
1111
1098
1112
if (arg2 == 0 )
1113
+ {
1099
1114
ereport (ERROR ,
1100
1115
(errcode (ERRCODE_DIVISION_BY_ZERO ),
1101
1116
errmsg ("division by zero" )));
1117
+ /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1118
+ PG_RETURN_NULL ();
1119
+ }
1102
1120
1103
1121
result = arg1 /arg2 ;
1104
1122
@@ -1121,9 +1139,14 @@ int4mod(PG_FUNCTION_ARGS)
1121
1139
int32 arg2 = PG_GETARG_INT32 (1 );
1122
1140
1123
1141
if (arg2 == 0 )
1142
+ {
1124
1143
ereport (ERROR ,
1125
1144
(errcode (ERRCODE_DIVISION_BY_ZERO ),
1126
1145
errmsg ("division by zero" )));
1146
+ /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1147
+ PG_RETURN_NULL ();
1148
+ }
1149
+
1127
1150
/* No overflow is possible */
1128
1151
1129
1152
PG_RETURN_INT32 (arg1 %arg2 );
@@ -1136,9 +1159,14 @@ int2mod(PG_FUNCTION_ARGS)
1136
1159
int16 arg2 = PG_GETARG_INT16 (1 );
1137
1160
1138
1161
if (arg2 == 0 )
1162
+ {
1139
1163
ereport (ERROR ,
1140
1164
(errcode (ERRCODE_DIVISION_BY_ZERO ),
1141
1165
errmsg ("division by zero" )));
1166
+ /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1167
+ PG_RETURN_NULL ();
1168
+ }
1169
+
1142
1170
/* No overflow is possible */
1143
1171
1144
1172
PG_RETURN_INT16 (arg1 %arg2 );
@@ -1151,9 +1179,14 @@ int24mod(PG_FUNCTION_ARGS)
1151
1179
int32 arg2 = PG_GETARG_INT32 (1 );
1152
1180
1153
1181
if (arg2 == 0 )
1182
+ {
1154
1183
ereport (ERROR ,
1155
1184
(errcode (ERRCODE_DIVISION_BY_ZERO ),
1156
1185
errmsg ("division by zero" )));
1186
+ /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1187
+ PG_RETURN_NULL ();
1188
+ }
1189
+
1157
1190
/* No overflow is possible */
1158
1191
1159
1192
PG_RETURN_INT32 (arg1 %arg2 );
@@ -1166,9 +1199,14 @@ int42mod(PG_FUNCTION_ARGS)
1166
1199
int16 arg2 = PG_GETARG_INT16 (1 );
1167
1200
1168
1201
if (arg2 == 0 )
1202
+ {
1169
1203
ereport (ERROR ,
1170
1204
(errcode (ERRCODE_DIVISION_BY_ZERO ),
1171
1205
errmsg ("division by zero" )));
1206
+ /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1207
+ PG_RETURN_NULL ();
1208
+ }
1209
+
1172
1210
/* No overflow is possible */
1173
1211
1174
1212
PG_RETURN_INT32 (arg1 %arg2 );