Skip to content

Commit 542eeba

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 0ea1f6e commit 542eeba

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
@@ -1690,8 +1690,9 @@ tm2timestamp(struct pg_tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
16901690
return -1;
16911691
}
16921692
/* check for just-barely overflow (okay except time-of-day wraps) */
1693-
if ((*result < 0 && date >= 0) ||
1694-
(*result >= 0 && date < 0))
1693+
/* caution: we want to allow 1999-12-31 24:00:00 */
1694+
if ((*result < 0 && date > 0) ||
1695+
(*result > 0 && date < -1))
16951696
{
16961697
*result = 0; /* keep compiler quiet */
16971698
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy