Skip to content

Commit 1ad3a7b

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 1856a0e commit 1ad3a7b

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
@@ -3083,10 +3083,11 @@ timetz_zone(PG_FUNCTION_ARGS)
30833083
result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
30843084

30853085
result->time = t->time + (t->zone - tz) * USECS_PER_SEC;
3086+
/* C99 modulo has the wrong sign convention for negative input */
30863087
while (result->time < INT64CONST(0))
30873088
result->time += USECS_PER_DAY;
3088-
while (result->time >= USECS_PER_DAY)
3089-
result->time -= USECS_PER_DAY;
3089+
if (result->time >= USECS_PER_DAY)
3090+
result->time %= USECS_PER_DAY;
30903091

30913092
result->zone = tz;
30923093

@@ -3116,10 +3117,11 @@ timetz_izone(PG_FUNCTION_ARGS)
31163117
result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
31173118

31183119
result->time = time->time + (time->zone - tz) * USECS_PER_SEC;
3120+
/* C99 modulo has the wrong sign convention for negative input */
31193121
while (result->time < INT64CONST(0))
31203122
result->time += USECS_PER_DAY;
3121-
while (result->time >= USECS_PER_DAY)
3122-
result->time -= USECS_PER_DAY;
3123+
if (result->time >= USECS_PER_DAY)
3124+
result->time %= USECS_PER_DAY;
31233125

31243126
result->zone = tz;
31253127

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