aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/numeric.c
diff options
context:
space:
mode:
authorFujii Masao <fujii@postgresql.org>2014-12-18 21:13:52 +0900
committerFujii Masao <fujii@postgresql.org>2014-12-18 21:13:52 +0900
commit19e065c0492c34fbccbd2c3707ba68cff14195a3 (patch)
treef34ea79704758b2adcaf1e8beafc4d77035d2b5a /src/backend/utils/adt/numeric.c
parentccf292cd2ec16c69ddfee3bf72afe113a7595e00 (diff)
downloadpostgresql-19e065c0492c34fbccbd2c3707ba68cff14195a3.tar.gz
postgresql-19e065c0492c34fbccbd2c3707ba68cff14195a3.zip
Ensure variables live across calls in generate_series(numeric, numeric).
In generate_series_step_numeric(), the variables "start_num" and "stop_num" may be potentially freed until the next call. So they should be put in the location which can survive across calls. But previously they were not, and which could cause incorrect behavior of generate_series(numeric, numeric). This commit fixes this problem by copying them on multi_call_memory_ctx. Andrew Gierth
Diffstat (limited to 'src/backend/utils/adt/numeric.c')
-rw-r--r--src/backend/utils/adt/numeric.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index c73f9bc005a..d841b6fa8b1 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -1325,11 +1325,16 @@ generate_series_step_numeric(PG_FUNCTION_ARGS)
/*
* Use fctx to keep state from call to call. Seed current with the
- * original start value.
+ * original start value. We must copy the start_num and stop_num
+ * values rather than pointing to them, since we may have detoasted
+ * them in the per-call context.
*/
- init_var_from_num(start_num, &fctx->current);
- init_var_from_num(stop_num, &fctx->stop);
+ init_var(&fctx->current);
+ init_var(&fctx->stop);
init_var(&fctx->step);
+
+ set_var_from_num(start_num, &fctx->current);
+ set_var_from_num(stop_num, &fctx->stop);
set_var_from_var(&steploc, &fctx->step);
funcctx->user_fctx = fctx;