@@ -36,8 +36,8 @@ typedef struct {
3636 PyObject * key ;
3737 PyObject * file_repr ;
3838 PyObject * weakreflist ;
39- unsigned int num_transitions ;
40- unsigned int num_ttinfos ;
39+ size_t num_transitions ;
40+ size_t num_ttinfos ;
4141 int64_t * trans_list_utc ;
4242 int64_t * trans_list_wall [2 ];
4343 _ttinfo * * trans_ttinfos ; // References to the ttinfo for each transition
@@ -117,14 +117,14 @@ ts_to_local(size_t *trans_idx, int64_t *trans_utc, long *utcoff,
117117static int
118118parse_tz_str (PyObject * tz_str_obj , _tzrule * out );
119119
120- static ssize_t
120+ static Py_ssize_t
121121parse_abbr (const char * const p , PyObject * * abbr );
122- static ssize_t
122+ static Py_ssize_t
123123parse_tz_delta (const char * const p , long * total_seconds );
124- static ssize_t
124+ static Py_ssize_t
125125parse_transition_time (const char * const p , int8_t * hour , int8_t * minute ,
126126 int8_t * second );
127- static ssize_t
127+ static Py_ssize_t
128128parse_transition_rule (const char * const p , TransitionRuleType * * out );
129129
130130static _ttinfo *
@@ -891,12 +891,12 @@ load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
891891
892892 // Load the relevant sizes
893893 Py_ssize_t num_transitions = PyTuple_Size (trans_utc );
894- if (num_transitions == -1 ) {
894+ if (num_transitions < 0 ) {
895895 goto error ;
896896 }
897897
898898 Py_ssize_t num_ttinfos = PyTuple_Size (utcoff_list );
899- if (num_ttinfos == -1 ) {
899+ if (num_ttinfos < 0 ) {
900900 goto error ;
901901 }
902902
@@ -908,7 +908,7 @@ load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
908908 PyMem_Malloc (self -> num_transitions * sizeof (int64_t ));
909909 trans_idx = PyMem_Malloc (self -> num_transitions * sizeof (Py_ssize_t ));
910910
911- for (Py_ssize_t i = 0 ; i < self -> num_transitions ; ++ i ) {
911+ for (size_t i = 0 ; i < self -> num_transitions ; ++ i ) {
912912 PyObject * num = PyTuple_GetItem (trans_utc , i );
913913 if (num == NULL ) {
914914 goto error ;
@@ -946,7 +946,7 @@ load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
946946 if (utcoff == NULL || isdst == NULL ) {
947947 goto error ;
948948 }
949- for (Py_ssize_t i = 0 ; i < self -> num_ttinfos ; ++ i ) {
949+ for (size_t i = 0 ; i < self -> num_ttinfos ; ++ i ) {
950950 PyObject * num = PyTuple_GetItem (utcoff_list , i );
951951 if (num == NULL ) {
952952 goto error ;
@@ -1468,7 +1468,7 @@ parse_tz_str(PyObject *tz_str_obj, _tzrule *out)
14681468 char * p = tz_str ;
14691469
14701470 // Read the `std` abbreviation, which must be at least 3 characters long.
1471- ssize_t num_chars = parse_abbr (p , & std_abbr );
1471+ Py_ssize_t num_chars = parse_abbr (p , & std_abbr );
14721472 if (num_chars < 1 ) {
14731473 PyErr_Format (PyExc_ValueError , "Invalid STD format in %R" , tz_str_obj );
14741474 goto error ;
@@ -1565,18 +1565,19 @@ parse_tz_str(PyObject *tz_str_obj, _tzrule *out)
15651565 return -1 ;
15661566}
15671567
1568- static ssize_t
1569- parse_uint (const char * const p )
1568+ static int
1569+ parse_uint (const char * const p , uint8_t * value )
15701570{
15711571 if (!isdigit (* p )) {
15721572 return -1 ;
15731573 }
15741574
1575- return (* p ) - '0' ;
1575+ * value = (* p ) - '0' ;
1576+ return 0 ;
15761577}
15771578
15781579/* Parse the STD and DST abbreviations from a TZ string. */
1579- static ssize_t
1580+ static Py_ssize_t
15801581parse_abbr (const char * const p , PyObject * * abbr )
15811582{
15821583 const char * ptr = p ;
@@ -1629,7 +1630,7 @@ parse_abbr(const char *const p, PyObject **abbr)
16291630}
16301631
16311632/* Parse a UTC offset from a TZ str. */
1632- static ssize_t
1633+ static Py_ssize_t
16331634parse_tz_delta (const char * const p , long * total_seconds )
16341635{
16351636 // From the POSIX spec:
@@ -1712,7 +1713,7 @@ parse_tz_delta(const char *const p, long *total_seconds)
17121713}
17131714
17141715/* Parse the date portion of a transition rule. */
1715- static ssize_t
1716+ static Py_ssize_t
17161717parse_transition_rule (const char * const p , TransitionRuleType * * out )
17171718{
17181719 // The full transition rule indicates when to change back and forth between
@@ -1739,20 +1740,18 @@ parse_transition_rule(const char *const p, TransitionRuleType **out)
17391740 if (* ptr == 'M' ) {
17401741 uint8_t month , week , day ;
17411742 ptr ++ ;
1742- ssize_t tmp = parse_uint (ptr );
1743- if (tmp < 0 ) {
1743+ if (parse_uint (ptr , & month )) {
17441744 return -1 ;
17451745 }
1746- month = (uint8_t )tmp ;
17471746 ptr ++ ;
17481747 if (* ptr != '.' ) {
1749- tmp = parse_uint ( ptr ) ;
1750- if (tmp < 0 ) {
1748+ uint8_t tmp ;
1749+ if (parse_uint ( ptr , & tmp ) ) {
17511750 return -1 ;
17521751 }
17531752
17541753 month *= 10 ;
1755- month += ( uint8_t ) tmp ;
1754+ month += tmp ;
17561755 ptr ++ ;
17571756 }
17581757
@@ -1763,18 +1762,15 @@ parse_transition_rule(const char *const p, TransitionRuleType **out)
17631762 }
17641763 ptr ++ ;
17651764
1766- tmp = parse_uint (ptr );
1767- if (tmp < 0 ) {
1765+ if (parse_uint (ptr , values [i ])) {
17681766 return -1 ;
17691767 }
17701768 ptr ++ ;
1771-
1772- * (values [i ]) = tmp ;
17731769 }
17741770
17751771 if (* ptr == '/' ) {
17761772 ptr ++ ;
1777- ssize_t num_chars =
1773+ Py_ssize_t num_chars =
17781774 parse_transition_time (ptr , & hour , & minute , & second );
17791775 if (num_chars < 0 ) {
17801776 return -1 ;
@@ -1816,7 +1812,7 @@ parse_transition_rule(const char *const p, TransitionRuleType **out)
18161812
18171813 if (* ptr == '/' ) {
18181814 ptr ++ ;
1819- ssize_t num_chars =
1815+ Py_ssize_t num_chars =
18201816 parse_transition_time (ptr , & hour , & minute , & second );
18211817 if (num_chars < 0 ) {
18221818 return -1 ;
@@ -1840,7 +1836,7 @@ parse_transition_rule(const char *const p, TransitionRuleType **out)
18401836}
18411837
18421838/* Parse the time portion of a transition rule (e.g. following an /) */
1843- static ssize_t
1839+ static Py_ssize_t
18441840parse_transition_time (const char * const p , int8_t * hour , int8_t * minute ,
18451841 int8_t * second )
18461842{
0 commit comments