Skip to content

Commit 7233099

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 have enabled it to break functions that weren't broken before. Aurelien Jarno, via Martin Pitt
1 parent 8acdb8b commit 7233099

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/backend/utils/adt/int8.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,13 @@ int8div(PG_FUNCTION_ARGS)
590590
int64 result;
591591

592592
if (arg2 == 0)
593+
{
593594
ereport(ERROR,
594595
(errcode(ERRCODE_DIVISION_BY_ZERO),
595596
errmsg("division by zero")));
597+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
598+
PG_RETURN_NULL();
599+
}
596600

597601
result = arg1 / arg2;
598602

@@ -637,9 +641,14 @@ int8mod(PG_FUNCTION_ARGS)
637641
int64 arg2 = PG_GETARG_INT64(1);
638642

639643
if (arg2 == 0)
644+
{
640645
ereport(ERROR,
641646
(errcode(ERRCODE_DIVISION_BY_ZERO),
642647
errmsg("division by zero")));
648+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
649+
PG_RETURN_NULL();
650+
}
651+
643652
/* No overflow is possible */
644653

645654
PG_RETURN_INT64(arg1 % arg2);
@@ -813,9 +822,13 @@ int84div(PG_FUNCTION_ARGS)
813822
int64 result;
814823

815824
if (arg2 == 0)
825+
{
816826
ereport(ERROR,
817827
(errcode(ERRCODE_DIVISION_BY_ZERO),
818828
errmsg("division by zero")));
829+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
830+
PG_RETURN_NULL();
831+
}
819832

820833
result = arg1 / arg2;
821834

@@ -997,9 +1010,13 @@ int82div(PG_FUNCTION_ARGS)
9971010
int64 result;
9981011

9991012
if (arg2 == 0)
1013+
{
10001014
ereport(ERROR,
10011015
(errcode(ERRCODE_DIVISION_BY_ZERO),
10021016
errmsg("division by zero")));
1017+
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
1018+
PG_RETURN_NULL();
1019+
}
10031020

10041021
result = arg1 / arg2;
10051022

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy