Skip to content

Commit bbcb75c

Browse files
authored
bpo-41839: Fix error checking in sched_get_priority_ functions (GH-22374)
1 parent 56eb6b6 commit bbcb75c

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Allow negative priority values from :func:`os.sched_get_priority_min` and
2+
:func:`os.sched_get_priority_max` functions.

Modules/posixmodule.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8211,10 +8211,10 @@ static PyObject *
82118211
os_sched_get_priority_max_impl(PyObject *module, int policy)
82128212
/*[clinic end generated code: output=9e465c6e43130521 input=2097b7998eca6874]*/
82138213
{
8214-
int max;
8215-
8216-
max = sched_get_priority_max(policy);
8217-
if (max < 0)
8214+
/* make sure that errno is cleared before the call */
8215+
errno = 0;
8216+
int max = sched_get_priority_max(policy);
8217+
if (max == -1 && errno)
82188218
return posix_error();
82198219
return PyLong_FromLong(max);
82208220
}
@@ -8232,8 +8232,10 @@ static PyObject *
82328232
os_sched_get_priority_min_impl(PyObject *module, int policy)
82338233
/*[clinic end generated code: output=7595c1138cc47a6d input=21bc8fa0d70983bf]*/
82348234
{
8235+
/* make sure that errno is cleared before the call */
8236+
errno = 0;
82358237
int min = sched_get_priority_min(policy);
8236-
if (min < 0)
8238+
if (min == -1 && errno)
82378239
return posix_error();
82388240
return PyLong_FromLong(min);
82398241
}

0 commit comments

Comments
 (0)