Aurelien Larcher
2021-01-08 b5a8497ec9558d0061024ac4b49f445bbe7d1094
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
https://github.com/python/cpython/pull/22374
 
From b415ba00a73229ad102d590226decea014be11cc Mon Sep 17 00:00:00 2001
From: Jakub Kulik <kulikjak@gmail.com>
Date: Fri, 6 Nov 2020 14:58:33 +0100
Subject: [PATCH 4/4] Make the error checking more robust
 
---
 Modules/posixmodule.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
 
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 82edeb39022b4..f8651d7f02bb4 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -6347,8 +6347,10 @@ os_sched_get_priority_max_impl(PyObject *module, int policy)
 {
     int max;
 
+    /* make sure that errno is cleared before the call */
+    errno = 0;
     max = sched_get_priority_max(policy);
-    if (max < 0)
+    if (max == -1 && errno == EINVAL)
         return posix_error();
     return PyLong_FromLong(max);
 }
@@ -6366,8 +6368,12 @@ static PyObject *
 os_sched_get_priority_min_impl(PyObject *module, int policy)
 /*[clinic end generated code: output=7595c1138cc47a6d input=21bc8fa0d70983bf]*/
 {
-    int min = sched_get_priority_min(policy);
-    if (min < 0)
+    int min;
+
+    /* make sure that errno is cleared before the call */
+    errno = 0;
+    min = sched_get_priority_min(policy);
+    if (min == -1 && errno == EINVAL)
         return posix_error();
     return PyLong_FromLong(min);
 }