diff --git a/src/backend/utils/adt/nabstime.c b/src/backend/utils/adt/nabstime.c index a6d30851df..6ec7ebafb8 100644 --- a/src/backend/utils/adt/nabstime.c +++ b/src/backend/utils/adt/nabstime.c @@ -105,6 +105,9 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn) else tx = pg_gmtime(&time); + if (tx == NULL) + elog(ERROR, "could not convert abstime to timestamp: %m"); + tm->tm_year = tx->tm_year + 1900; tm->tm_mon = tx->tm_mon + 1; tm->tm_mday = tx->tm_mday; diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index 5ca2fad451..d24ab8560c 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -2150,6 +2150,9 @@ GetEpochTime(struct pg_tm * tm) t0 = pg_gmtime(&epoch); + if (t0 == NULL) + elog(ERROR, "could not convert epoch to timestamp: %m"); + tm->tm_year = t0->tm_year; tm->tm_mon = t0->tm_mon; tm->tm_mday = t0->tm_mday; diff --git a/src/timezone/localtime.c b/src/timezone/localtime.c index 31b06b037f..a2260e590d 100644 --- a/src/timezone/localtime.c +++ b/src/timezone/localtime.c @@ -1328,13 +1328,14 @@ gmtsub(pg_time_t const *timep, int32 offset, struct pg_tm *tmp) struct pg_tm *result; /* GMT timezone state data is kept here */ - static struct state gmtmem; - static bool gmt_is_set = false; -#define gmtptr (&gmtmem) + static struct state *gmtptr = NULL; - if (!gmt_is_set) + if (gmtptr == NULL) { - gmt_is_set = true; + /* Allocate on first use */ + gmtptr = (struct state *) malloc(sizeof(struct state)); + if (gmtptr == NULL) + return NULL; /* errno should be set by malloc */ gmtload(gmtptr); } result = timesub(timep, offset, gmtptr, tmp);