Skip to content

Commit 062780e

Browse files
committed
Add overflow checks to int4 and int8 versions of generate_series().
The previous code went into an infinite loop after overflow. In fact, an overflow is not really an error; it just means that the current value is the last one we need to return. So, just arrange to stop immediately when overflow is detected. Back-patch all the way.
1 parent bf347c6 commit 062780e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/backend/utils/adt/int.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,10 @@ generate_series_step_int4(PG_FUNCTION_ARGS)
13821382
/* increment current in preparation for next iteration */
13831383
fctx->current += fctx->step;
13841384

1385+
/* if next-value computation overflows, this is the final result */
1386+
if (SAMESIGN(result, fctx->step) && !SAMESIGN(result, fctx->current))
1387+
fctx->step = 0;
1388+
13851389
/* do when there is more left to send */
13861390
SRF_RETURN_NEXT(funcctx, Int32GetDatum(result));
13871391
}

src/backend/utils/adt/int8.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,10 @@ generate_series_step_int8(PG_FUNCTION_ARGS)
14101410
/* increment current in preparation for next iteration */
14111411
fctx->current += fctx->step;
14121412

1413+
/* if next-value computation overflows, this is the final result */
1414+
if (SAMESIGN(result, fctx->step) && !SAMESIGN(result, fctx->current))
1415+
fctx->step = 0;
1416+
14131417
/* do when there is more left to send */
14141418
SRF_RETURN_NEXT(funcctx, Int64GetDatum(result));
14151419
}

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