From 3d880ecd2b28e56cfd7b73193bc292ae3e4a8e18 Mon Sep 17 00:00:00 2001 From: Sven Klemm Date: Tue, 1 Sep 2020 23:16:37 +0200 Subject: [PATCH] Fix segfault in caggs on 32-bit systems While DatumGetInt64 and Int64GetDatum are noops on 64-bit systems calling them on the wrong underlying type can lead to segfaults on 32-bit systems. --- tsl/src/continuous_aggs/create.c | 3 ++- tsl/src/continuous_aggs/refresh.c | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tsl/src/continuous_aggs/create.c b/tsl/src/continuous_aggs/create.c index c39ca69af..5741a133f 100644 --- a/tsl/src/continuous_aggs/create.c +++ b/tsl/src/continuous_aggs/create.c @@ -515,7 +515,8 @@ mattablecolumninfo_create_materialization_table(MatTableColumnInfo *matcolinfo, /* Initialize the invalidation log for the cagg. Initially, everything is * invalid. */ if (OidIsValid(origquery_tblinfo->nowfunc)) - current_time = DatumGetInt64(OidFunctionCall0(origquery_tblinfo->nowfunc)); + current_time = ts_time_value_to_internal(OidFunctionCall0(origquery_tblinfo->nowfunc), + get_func_rettype(origquery_tblinfo->nowfunc)); else current_time = GetCurrentTransactionStartTimestamp(); diff --git a/tsl/src/continuous_aggs/refresh.c b/tsl/src/continuous_aggs/refresh.c index a3fc271ea..17450fb48 100644 --- a/tsl/src/continuous_aggs/refresh.c +++ b/tsl/src/continuous_aggs/refresh.c @@ -207,10 +207,10 @@ continuous_agg_refresh_with_window(ContinuousAgg *cagg, const InternalTimeRange if (client_min_messages <= DEBUG1) { - Datum start_ts = ts_internal_to_time_value(DatumGetInt64(bucketed_refresh_window.start), - refresh_window->type); - Datum end_ts = ts_internal_to_time_value(DatumGetInt64(bucketed_refresh_window.end), - refresh_window->type); + Datum start_ts = + ts_internal_to_time_value(bucketed_refresh_window.start, refresh_window->type); + Datum end_ts = + ts_internal_to_time_value(bucketed_refresh_window.end, refresh_window->type); Oid outfuncid = InvalidOid; bool isvarlena;