Skip to content

[3.9] bpo-40686: Fix compiler warnings on _zoneinfo.c (GH-23614) #23804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2020
Merged
Changes from all commits
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
14 changes: 4 additions & 10 deletions Modules/_zoneinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static void
update_strong_cache(const PyTypeObject *const type, PyObject *key,
PyObject *zone);
static PyObject *
zone_from_strong_cache(const PyTypeObject *const type, PyObject *key);
zone_from_strong_cache(const PyTypeObject *const type, PyObject *const key);

static PyObject *
zoneinfo_new_instance(PyTypeObject *type, PyObject *key)
Expand Down Expand Up @@ -1219,15 +1219,9 @@ calendarrule_new(uint8_t month, uint8_t week, uint8_t day, int8_t hour,
return -1;
}

// day is an unsigned integer, so day < 0 should always return false, but
// if day's type changes to a signed integer *without* changing this value,
// it may create a bug. Considering that the compiler should be able to
// optimize out the first comparison if day is an unsigned integer anyway,
// we will leave this comparison in place and disable the compiler warning.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtype-limits"
if (day < 0 || day > 6) {
#pragma GCC diagnostic pop
// If the 'day' parameter type is changed to a signed type,
// "day < 0" check must be added.
if (/* day < 0 || */ day > 6) {
PyErr_Format(PyExc_ValueError, "Day must be in [0, 6]");
return -1;
}
Expand Down