Skip to content

Commit e98f47d

Browse files
committed
Dodge a compiler bug affecting timetz_zone/timetz_izone.
This avoids a compiler bug occurring in AIX's xlc, even in pretty late-model revisions. Buildfarm testing has now confirmed that only 64-bit xlc is affected. Although we are contemplating dropping support for xlc in v17, it's still supported in the back branches, so we need this fix. Back-patch of code changes from HEAD commit 19fa977. (The test cases were already back-patched, in 4a427b8 et al.) Discussion: https://postgr.es/m/CA+hUKGK=DOC+hE-62FKfZy=Ybt5uLkrg3zCZD-jFykM-iPn8yw@mail.gmail.com
1 parent 32d3118 commit e98f47d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/backend/utils/adt/date.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,10 +2877,11 @@ timetz_zone(PG_FUNCTION_ARGS)
28772877
result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
28782878

28792879
result->time = t->time + (t->zone - tz) * USECS_PER_SEC;
2880+
/* C99 modulo has the wrong sign convention for negative input */
28802881
while (result->time < INT64CONST(0))
28812882
result->time += USECS_PER_DAY;
2882-
while (result->time >= USECS_PER_DAY)
2883-
result->time -= USECS_PER_DAY;
2883+
if (result->time >= USECS_PER_DAY)
2884+
result->time %= USECS_PER_DAY;
28842885

28852886
result->zone = tz;
28862887

@@ -2910,10 +2911,11 @@ timetz_izone(PG_FUNCTION_ARGS)
29102911
result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
29112912

29122913
result->time = time->time + (time->zone - tz) * USECS_PER_SEC;
2914+
/* C99 modulo has the wrong sign convention for negative input */
29132915
while (result->time < INT64CONST(0))
29142916
result->time += USECS_PER_DAY;
2915-
while (result->time >= USECS_PER_DAY)
2916-
result->time -= USECS_PER_DAY;
2917+
if (result->time >= USECS_PER_DAY)
2918+
result->time %= USECS_PER_DAY;
29172919

29182920
result->zone = tz;
29192921

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