Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update PR with backport changes
  • Loading branch information
pablogsal committed May 27, 2020
commit 245bc7ac3de704ac1f935bdc06c1e4d166c2d082
34 changes: 15 additions & 19 deletions Modules/_zoneinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -891,17 +891,17 @@ load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj)

// Load the relevant sizes
Py_ssize_t num_transitions = PyTuple_Size(trans_utc);
if (num_transitions == -1) {
if (num_transitions < 0) {
goto error;
}

Py_ssize_t num_ttinfos = PyTuple_Size(utcoff_list);
if (num_ttinfos == -1) {
if (num_ttinfos < 0) {
goto error;
}

self->num_transitions = num_transitions;
self->num_ttinfos = num_ttinfos;
self->num_transitions = (size_t)num_transitions;
self->num_ttinfos = (size_t)num_ttinfos;

// Load the transition indices and list
self->trans_list_utc =
Expand Down Expand Up @@ -1565,14 +1565,15 @@ parse_tz_str(PyObject *tz_str_obj, _tzrule *out)
return -1;
}

static Py_ssize_t
parse_uint(const char *const p)
static int
parse_uint(const char *const p, uint8_t *value)
{
if (!isdigit(*p)) {
return -1;
}

return (*p) - '0';
*value = (*p) - '0';
return 0;
}

/* Parse the STD and DST abbreviations from a TZ string. */
Expand Down Expand Up @@ -1737,39 +1738,34 @@ parse_transition_rule(const char *const p, TransitionRuleType **out)
// 3. Mm.n.d: Specifying by month, week and day-of-week.

if (*ptr == 'M') {
Py_ssize_t month, week, day;
uint8_t month, week, day;
ptr++;
Py_ssize_t tmp = parse_uint(ptr);
if (tmp < 0) {
if (parse_uint(ptr, &month)) {
return -1;
}
month = tmp;
ptr++;
if (*ptr != '.') {
tmp = parse_uint(ptr);
if (tmp < 0) {
uint8_t tmp;
if (parse_uint(ptr, &tmp)) {
return -1;
}

month *= 10;
month += (uint8_t)tmp;
month += tmp;
ptr++;
}

Py_ssize_t *values[2] = {&week, &day};
uint8_t *values[2] = {&week, &day};
for (size_t i = 0; i < 2; ++i) {
if (*ptr != '.') {
return -1;
}
ptr++;

tmp = parse_uint(ptr);
if (tmp < 0) {
if (parse_uint(ptr, values[i])) {
return -1;
}
ptr++;

*(values[i]) = tmp;
}

if (*ptr == '/') {
Expand Down