23
23
typedef int64 zic_t ;
24
24
#define ZIC_MIN PG_INT64_MIN
25
25
#define ZIC_MAX PG_INT64_MAX
26
- #define SCNdZIC INT64_MODIFIER "d"
27
26
28
27
#ifndef ZIC_MAX_ABBR_LEN_WO_WARN
29
28
#define ZIC_MAX_ABBR_LEN_WO_WARN 6
@@ -1145,7 +1144,8 @@ infile(const char *name)
1145
1144
static zic_t
1146
1145
gethms (char const * string , char const * errstring , bool signable )
1147
1146
{
1148
- zic_t hh ;
1147
+ /* PG: make hh be int not zic_t to avoid sscanf portability issues */
1148
+ int hh ;
1149
1149
int mm ,
1150
1150
ss ,
1151
1151
sign ;
@@ -1162,11 +1162,11 @@ gethms(char const * string, char const * errstring, bool signable)
1162
1162
}
1163
1163
else
1164
1164
sign = 1 ;
1165
- if (sscanf (string , "%" SCNdZIC " %c" , & hh , & xs ) == 1 )
1165
+ if (sscanf (string , "%d %c" , & hh , & xs ) == 1 )
1166
1166
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 )
1168
1168
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 )
1170
1170
!= 3 )
1171
1171
{
1172
1172
error ("%s" , errstring );
@@ -1179,15 +1179,15 @@ gethms(char const * string, char const * errstring, bool signable)
1179
1179
error ("%s" , errstring );
1180
1180
return 0 ;
1181
1181
}
1182
- if (ZIC_MAX / SECSPERHOUR < hh )
1182
+ if (ZIC_MAX / SECSPERHOUR < ( zic_t ) hh )
1183
1183
{
1184
1184
error (_ ("time overflow" ));
1185
1185
return 0 ;
1186
1186
}
1187
1187
if (noise && (hh > HOURSPERDAY ||
1188
1188
(hh == HOURSPERDAY && (mm != 0 || ss != 0 ))))
1189
1189
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 ,
1191
1191
sign * (mm * SECSPERMIN + ss ));
1192
1192
}
1193
1193
@@ -1374,7 +1374,9 @@ inleap(char **fields, int nfields)
1374
1374
const struct lookup * lp ;
1375
1375
int i ,
1376
1376
j ;
1377
- zic_t year ;
1377
+
1378
+ /* PG: make year be int not zic_t to avoid sscanf portability issues */
1379
+ int year ;
1378
1380
int month ,
1379
1381
day ;
1380
1382
zic_t dayoff ,
@@ -1389,7 +1391,7 @@ inleap(char **fields, int nfields)
1389
1391
}
1390
1392
dayoff = 0 ;
1391
1393
cp = fields [LP_YEAR ];
1392
- if (sscanf (cp , "%" SCNdZIC " %c" , & year , & xs ) != 1 )
1394
+ if (sscanf (cp , "%d %c" , & year , & xs ) != 1 )
1393
1395
{
1394
1396
/*
1395
1397
* Leapin' Lizards!
@@ -1531,6 +1533,9 @@ rulesub(struct rule * rp, const char *loyearp, const char *hiyearp,
1531
1533
char * ep ;
1532
1534
char xs ;
1533
1535
1536
+ /* PG: year_tmp is to avoid sscanf portability issues */
1537
+ int year_tmp ;
1538
+
1534
1539
if ((lp = byword (monthp , mon_names )) == NULL )
1535
1540
{
1536
1541
error (_ ("invalid month name" ));
@@ -1588,7 +1593,9 @@ rulesub(struct rule * rp, const char *loyearp, const char *hiyearp,
1588
1593
progname , lp -> l_value );
1589
1594
exit (EXIT_FAILURE );
1590
1595
}
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
1592
1599
{
1593
1600
error (_ ("invalid starting year" ));
1594
1601
return ;
@@ -1614,7 +1621,9 @@ rulesub(struct rule * rp, const char *loyearp, const char *hiyearp,
1614
1621
progname , lp -> l_value );
1615
1622
exit (EXIT_FAILURE );
1616
1623
}
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
1618
1627
{
1619
1628
error (_ ("invalid ending year" ));
1620
1629
return ;
0 commit comments