diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2013-03-04 15:13:31 -0500 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2013-03-04 15:14:13 -0500 |
| commit | da5f032a8350a77aeed4f9d459633055f0adb645 (patch) | |
| tree | 77787cbd2c344da166737e9f159953daccb5d83a | |
| parent | ffc9daf90549c4412c2ffd82532eb84ca17f5e14 (diff) | |
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.
| -rw-r--r-- | src/backend/utils/adt/timestamp.c | 5 | ||||
| -rw-r--r-- | src/interfaces/ecpg/pgtypeslib/timestamp.c | 5 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index a0c5a6ab66a..88c3f7d262b 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -1564,8 +1564,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 315c683455a..46084fe8769 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; |
