Skip to content

Commit 85c9dda

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 19fa97731. (The test cases were already back-patched, in 4a427b82c et al.) Discussion: https://postgr.es/m/CA+hUKGK=DOC+hE-62FKfZy=Ybt5uLkrg3zCZD-jFykM-iPn8yw@mail.gmail.com
1 parent 9208c6f commit 85c9dda

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

31043104
result->time = t->time + (t->zone - tz) * USECS_PER_SEC;
3105+
/* C99 modulo has the wrong sign convention for negative input */
31053106
while (result->time < INT64CONST(0))
31063107
result->time += USECS_PER_DAY;
3107-
while (result->time >= USECS_PER_DAY)
3108-
result->time -= USECS_PER_DAY;
3108+
if (result->time >= USECS_PER_DAY)
3109+
result->time %= USECS_PER_DAY;
31093110

31103111
result->zone = tz;
31113112

@@ -3135,10 +3136,11 @@ timetz_izone(PG_FUNCTION_ARGS)
31353136
result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
31363137

31373138
result->time = time->time + (time->zone - tz) * USECS_PER_SEC;
3139+
/* C99 modulo has the wrong sign convention for negative input */
31383140
while (result->time < INT64CONST(0))
31393141
result->time += USECS_PER_DAY;
3140-
while (result->time >= USECS_PER_DAY)
3141-
result->time -= USECS_PER_DAY;
3142+
if (result->time >= USECS_PER_DAY)
3143+
result->time %= USECS_PER_DAY;
31423144

31433145
result->zone = tz;
31443146

0 commit comments

Comments
 (0)