From b1475317954276eb2daa7aaaa7d3baffcdd39247 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Tue, 7 Jul 2015 16:11:48 +0900
Subject: [PATCH 4/4] Check return values of timestamp2tm

All the other code paths are doing similar checks, and even if this is
a minor problem it is better to be consistent with the rest to prevent
future problems.
Spotted by Coverity.
---
 src/backend/utils/adt/datetime.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 2a44b6e..fe0ba80 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -371,8 +371,11 @@ GetCurrentDateTime(struct pg_tm * tm)
 	int			tz;
 	fsec_t		fsec;
 
-	timestamp2tm(GetCurrentTransactionStartTimestamp(), &tz, tm, &fsec,
-				 NULL, NULL);
+	if (timestamp2tm(GetCurrentTransactionStartTimestamp(), &tz, tm, &fsec,
+					 NULL, NULL) != 0)
+		ereport(ERROR,
+				(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+				 errmsg("timestamp out of range")));
 	/* Note: don't pass NULL tzp to timestamp2tm; affects behavior */
 }
 
@@ -387,8 +390,11 @@ GetCurrentTimeUsec(struct pg_tm * tm, fsec_t *fsec, int *tzp)
 {
 	int			tz;
 
-	timestamp2tm(GetCurrentTransactionStartTimestamp(), &tz, tm, fsec,
-				 NULL, NULL);
+	if (timestamp2tm(GetCurrentTransactionStartTimestamp(), &tz, tm, fsec,
+					 NULL, NULL) != 0)
+		ereport(ERROR,
+				(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+				 errmsg("timestamp out of range")));
 	/* Note: don't pass NULL tzp to timestamp2tm; affects behavior */
 	if (tzp != NULL)
 		*tzp = tz;
-- 
2.4.5

