Skip to content

Commit 478c95a

Browse files
committed
Prevent timetz2tm() from scribbling on its input in HAVE_INT64_TIMESTAMP case.
1 parent 1a9b061 commit 478c95a

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/backend/utils/adt/date.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.78 2003/01/31 01:08:08 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.79 2003/02/13 17:04:19 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1349,23 +1349,22 @@ timetz_out(PG_FUNCTION_ARGS)
13491349

13501350
/* timetz2tm()
13511351
* Convert TIME WITH TIME ZONE data type to POSIX time structure.
1352-
* For dates within the system-supported time_t range, convert to the
1353-
* local time zone. If out of this range, leave as GMT. - tgl 97/05/27
13541352
*/
13551353
static int
13561354
timetz2tm(TimeTzADT *time, struct tm * tm, fsec_t *fsec, int *tzp)
13571355
{
13581356
#ifdef HAVE_INT64_TIMESTAMP
1359-
tm->tm_hour = (time->time / INT64CONST(3600000000));
1360-
time->time -= (tm->tm_hour * INT64CONST(3600000000));
1361-
tm->tm_min = (time->time / INT64CONST(60000000));
1362-
time->time -= (tm->tm_min * INT64CONST(60000000));
1363-
tm->tm_sec = (time->time / INT64CONST(1000000));
1364-
*fsec = (time->time - (tm->tm_sec * INT64CONST(1000000)));
1357+
int64 trem = time->time;
1358+
1359+
tm->tm_hour = (trem / INT64CONST(3600000000));
1360+
trem -= (tm->tm_hour * INT64CONST(3600000000));
1361+
tm->tm_min = (trem / INT64CONST(60000000));
1362+
trem -= (tm->tm_min * INT64CONST(60000000));
1363+
tm->tm_sec = (trem / INT64CONST(1000000));
1364+
*fsec = (trem - (tm->tm_sec * INT64CONST(1000000)));
13651365
#else
1366-
double trem;
1366+
double trem = time->time;
13671367

1368-
trem = time->time;
13691368
TMODULO(trem, tm->tm_hour, 3600e0);
13701369
TMODULO(trem, tm->tm_min, 60e0);
13711370
TMODULO(trem, tm->tm_sec, 1e0);

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