@@ -723,9 +723,13 @@ int4div(PG_FUNCTION_ARGS)
723723int32 result ;
724724
725725if (arg2 == 0 )
726+ {
726727ereport (ERROR ,
727728(errcode (ERRCODE_DIVISION_BY_ZERO ),
728729errmsg ("division by zero" )));
730+ /* ensure compiler realizes we mustn't reach the division (gcc bug) */
731+ PG_RETURN_NULL ();
732+ }
729733
730734#ifdef WIN32
731735
@@ -864,9 +868,13 @@ int2div(PG_FUNCTION_ARGS)
864868int16 result ;
865869
866870if (arg2 == 0 )
871+ {
867872ereport (ERROR ,
868873(errcode (ERRCODE_DIVISION_BY_ZERO ),
869874errmsg ("division by zero" )));
875+ /* ensure compiler realizes we mustn't reach the division (gcc bug) */
876+ PG_RETURN_NULL ();
877+ }
870878
871879result = arg1 /arg2 ;
872880
@@ -1048,9 +1056,13 @@ int42div(PG_FUNCTION_ARGS)
10481056int32 result ;
10491057
10501058if (arg2 == 0 )
1059+ {
10511060ereport (ERROR ,
10521061(errcode (ERRCODE_DIVISION_BY_ZERO ),
10531062errmsg ("division by zero" )));
1063+ /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1064+ PG_RETURN_NULL ();
1065+ }
10541066
10551067result = arg1 /arg2 ;
10561068
@@ -1074,9 +1086,13 @@ int4mod(PG_FUNCTION_ARGS)
10741086int32 arg2 = PG_GETARG_INT32 (1 );
10751087
10761088if (arg2 == 0 )
1089+ {
10771090ereport (ERROR ,
10781091(errcode (ERRCODE_DIVISION_BY_ZERO ),
10791092errmsg ("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 */
10821098if (arg1 == INT_MIN && arg2 == -1 )
@@ -1094,9 +1110,14 @@ int2mod(PG_FUNCTION_ARGS)
10941110int16 arg2 = PG_GETARG_INT16 (1 );
10951111
10961112if (arg2 == 0 )
1113+ {
10971114ereport (ERROR ,
10981115(errcode (ERRCODE_DIVISION_BY_ZERO ),
10991116errmsg ("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
11021123PG_RETURN_INT16 (arg1 %arg2 );