From: Tom Lane Date: Mon, 4 Mar 2013 20:13:31 +0000 (-0500) Subject: Fix overflow check in tm2timestamp (this time for sure). X-Git-Tag: REL8_4_17~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cf678140548b0f0fdef36f314bb84e07e15b8c16;p=postgresql Fix overflow check in tm2timestamp (this time for sure). I fixed this code back in commit 841b4a2d5, but didn't think carefully enough about the behavior near zero, which meant it improperly rejected 1999-12-31 24:00:00. Per report from Magnus Hagander. --- diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index f4687d4ea9..fdd0cf4393 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -1559,8 +1559,9 @@ tm2timestamp(struct pg_tm * tm, fsec_t fsec, int *tzp, Timestamp *result) return -1; } /* check for just-barely overflow (okay except time-of-day wraps) */ - if ((*result < 0 && date >= 0) || - (*result >= 0 && date < 0)) + /* caution: we want to allow 1999-12-31 24:00:00 */ + if ((*result < 0 && date > 0) || + (*result > 0 && date < -1)) { *result = 0; /* keep compiler quiet */ return -1; diff --git a/src/interfaces/ecpg/pgtypeslib/timestamp.c b/src/interfaces/ecpg/pgtypeslib/timestamp.c index 22e3ce7273..f50feaf9cf 100644 --- a/src/interfaces/ecpg/pgtypeslib/timestamp.c +++ b/src/interfaces/ecpg/pgtypeslib/timestamp.c @@ -76,8 +76,9 @@ tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, timestamp * result) if ((*result - time) / USECS_PER_DAY != dDate) return -1; /* check for just-barely overflow (okay except time-of-day wraps) */ - if ((*result < 0 && dDate >= 0) || - (*result >= 0 && dDate < 0)) + /* caution: we want to allow 1999-12-31 24:00:00 */ + if ((*result < 0 && dDate > 0) || + (*result > 0 && dDate < -1)) return -1; #else *result = dDate * SECS_PER_DAY + time;