Skip to content

Commit d8c2877

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 ed697c4 commit d8c2877

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

28322832
result->time = t->time + (t->zone - tz) * USECS_PER_SEC;
2833+
/* C99 modulo has the wrong sign convention for negative input */
28332834
while (result->time < INT64CONST(0))
28342835
result->time += USECS_PER_DAY;
2835-
while (result->time >= USECS_PER_DAY)
2836-
result->time -= USECS_PER_DAY;
2836+
if (result->time >= USECS_PER_DAY)
2837+
result->time %= USECS_PER_DAY;
28372838

28382839
result->zone = tz;
28392840

@@ -2863,10 +2864,11 @@ timetz_izone(PG_FUNCTION_ARGS)
28632864
result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
28642865

28652866
result->time = time->time + (time->zone - tz) * USECS_PER_SEC;
2867+
/* C99 modulo has the wrong sign convention for negative input */
28662868
while (result->time < INT64CONST(0))
28672869
result->time += USECS_PER_DAY;
2868-
while (result->time >= USECS_PER_DAY)
2869-
result->time -= USECS_PER_DAY;
2870+
if (result->time >= USECS_PER_DAY)
2871+
result->time %= USECS_PER_DAY;
28702872

28712873
result->zone = tz;
28722874

0 commit comments

Comments
 (0)