8000 Fix overflow check in tm2timestamp (this time for sure). · danielcode/postgres@fa85230 · GitHub
[go: up one dir, main page]

Skip to content

Commit fa85230

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 d4f4bdf commit fa85230

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
@@ -1646,8 +1646,9 @@ tm2timestamp(struct pg_tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
16461646
return -1;
16471647
}
16481648
/* check for just-barely overflow (okay except time-of-day wraps) */
1649-
if ((*result < 0 && date >= 0) ||
1650-
(*result >= 0 && date < 0))
1649+
/* caution: we want to allow 1999-12-31 24:00:00 */
1650+
if ((*result < 0 && date > 0) ||
1651+
(*result > 0 && date < -1))
16511652
{
16521653
*result = 0; /* keep compiler quiet */
16531654
return -1;

src/interfaces/ecpg/pgtypeslib/timestamp.c

Lines changed: 3 additions & 2 deletions
6CD8
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)
0