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

Commit062780e

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 currentvalue is the last one we need to return. So, just arrange to stopimmediately when overflow is detected.Back-patch all the way.
1 parentbf347c6 commit062780e

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)

[8]ページ先頭

©2009-2025 Movatter.jp