Skip to content

Commit da5f032

Browse files
committed
Fix overflow check in tm2timestamp (this time for sure).
I fixed this code back in commit 841b4a2, 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.
1 parent ffc9daf commit da5f032

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/backend/utils/adt/timestamp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,8 +1564,9 @@ tm2timestamp(struct pg_tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
15641564
return -1;
15651565
}
15661566
/* check for just-barely overflow (okay except time-of-day wraps) */
1567-
if ((*result < 0 && date >= 0) ||
1568-
(*result >= 0 && date < 0))
1567+
/* caution: we want to allow 1999-12-31 24:00:00 */
1568+
if ((*result < 0 && date > 0) ||
1569+
(*result > 0 && date < -1))
15691570
{
15701571
*result = 0; /* keep compiler quiet */
15711572
return -1;

src/interfaces/ecpg/pgtypeslib/timestamp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, timestamp * result)
7676
if ((*result - time) / USECS_PER_DAY != dDate)
7777
return -1;
7878
/* check for just-barely overflow (okay except time-of-day wraps) */
79-
if ((*result < 0 && dDate >= 0) ||
80-
(*result >= 0 && dDate < 0))
79+
/* caution: we want to allow 1999-12-31 24:00:00 */
80+
if ((*result < 0 && dDate > 0) ||
81+
(*result > 0 && dDate < -1))
8182
return -1;
8283
#else
8384
*result = dDate * SECS_PER_DAY + time;

0 commit comments

Comments
 (0)