Skip to content

Commit c202ecf

Browse files
committed
Another zic portability fix.
I should have remembered that we can't use INT64_MODIFIER with sscanf(): configure chooses that to work with snprintf(), but it might be for our src/port/snprintf.c implementation and so not compatible with the platform's sscanf(). This appears to be the explanation for buildfarm member frogmouth's continuing unhappiness with the tzcode update. Fortunately, in all of the places where zic is attempting to read into an int64 variable, it's reading a year which certainly will fit just fine into an int. So make it read into an int with %d, and then cast or copy as necessary.
1 parent 61608d3 commit c202ecf

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/timezone/zic.c

+20-11
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
typedef int64 zic_t;
2424
#define ZIC_MIN PG_INT64_MIN
2525
#define ZIC_MAX PG_INT64_MAX
26-
#define SCNdZIC INT64_MODIFIER "d"
2726

2827
#ifndef ZIC_MAX_ABBR_LEN_WO_WARN
2928
#define ZIC_MAX_ABBR_LEN_WO_WARN 6
@@ -1145,7 +1144,8 @@ infile(const char *name)
11451144
static zic_t
11461145
gethms(char const * string, char const * errstring, bool signable)
11471146
{
1148-
zic_t hh;
1147+
/* PG: make hh be int not zic_t to avoid sscanf portability issues */
1148+
int hh;
11491149
int mm,
11501150
ss,
11511151
sign;
@@ -1162,11 +1162,11 @@ gethms(char const * string, char const * errstring, bool signable)
11621162
}
11631163
else
11641164
sign = 1;
1165-
if (sscanf(string, "%" SCNdZIC "%c", &hh, &xs) == 1)
1165+
if (sscanf(string, "%d%c", &hh, &xs) == 1)
11661166
mm = ss = 0;
1167-
else if (sscanf(string, "%" SCNdZIC ":%d%c", &hh, &mm, &xs) == 2)
1167+
else if (sscanf(string, "%d:%d%c", &hh, &mm, &xs) == 2)
11681168
ss = 0;
1169-
else if (sscanf(string, "%" SCNdZIC ":%d:%d%c", &hh, &mm, &ss, &xs)
1169+
else if (sscanf(string, "%d:%d:%d%c", &hh, &mm, &ss, &xs)
11701170
!= 3)
11711171
{
11721172
error("%s", errstring);
@@ -1179,15 +1179,15 @@ gethms(char const * string, char const * errstring, bool signable)
11791179
error("%s", errstring);
11801180
return 0;
11811181
}
1182-
if (ZIC_MAX / SECSPERHOUR < hh)
1182+
if (ZIC_MAX / SECSPERHOUR < (zic_t) hh)
11831183
{
11841184
error(_("time overflow"));
11851185
return 0;
11861186
}
11871187
if (noise && (hh > HOURSPERDAY ||
11881188
(hh == HOURSPERDAY && (mm != 0 || ss != 0))))
11891189
warning(_("values over 24 hours not handled by pre-2007 versions of zic"));
1190-
return oadd(sign * hh * SECSPERHOUR,
1190+
return oadd(sign * (zic_t) hh * SECSPERHOUR,
11911191
sign * (mm * SECSPERMIN + ss));
11921192
}
11931193

@@ -1374,7 +1374,9 @@ inleap(char **fields, int nfields)
13741374
const struct lookup *lp;
13751375
int i,
13761376
j;
1377-
zic_t year;
1377+
1378+
/* PG: make year be int not zic_t to avoid sscanf portability issues */
1379+
int year;
13781380
int month,
13791381
day;
13801382
zic_t dayoff,
@@ -1389,7 +1391,7 @@ inleap(char **fields, int nfields)
13891391
}
13901392
dayoff = 0;
13911393
cp = fields[LP_YEAR];
1392-
if (sscanf(cp, "%" SCNdZIC "%c", &year, &xs) != 1)
1394+
if (sscanf(cp, "%d%c", &year, &xs) != 1)
13931395
{
13941396
/*
13951397
* Leapin' Lizards!
@@ -1531,6 +1533,9 @@ rulesub(struct rule * rp, const char *loyearp, const char *hiyearp,
15311533
char *ep;
15321534
char xs;
15331535

1536+
/* PG: year_tmp is to avoid sscanf portability issues */
1537+
int year_tmp;
1538+
15341539
if ((lp = byword(monthp, mon_names)) == NULL)
15351540
{
15361541
error(_("invalid month name"));
@@ -1588,7 +1593,9 @@ rulesub(struct rule * rp, const char *loyearp, const char *hiyearp,
15881593
progname, lp->l_value);
15891594
exit(EXIT_FAILURE);
15901595
}
1591-
else if (sscanf(cp, "%" SCNdZIC "%c", &rp->r_loyear, &xs) != 1)
1596+
else if (sscanf(cp, "%d%c", &year_tmp, &xs) == 1)
1597+
rp->r_loyear = year_tmp;
1598+
else
15921599
{
15931600
error(_("invalid starting year"));
15941601
return;
@@ -1614,7 +1621,9 @@ rulesub(struct rule * rp, const char *loyearp, const char *hiyearp,
16141621
progname, lp->l_value);
16151622
exit(EXIT_FAILURE);
16161623
}
1617-
else if (sscanf(cp, "%" SCNdZIC "%c", &rp->r_hiyear, &xs) != 1)
1624+
else if (sscanf(cp, "%d%c", &year_tmp, &xs) == 1)
1625+
rp->r_hiyear = year_tmp;
1626+
else
16181627
{
16191628
error(_("invalid ending year"));
16201629
return;

0 commit comments

Comments
 (0)