# HG changeset patch
# Parent bd556f748cf8187c26d6e2a40986efbf557b4643
Issue #1621: Avoid overflow detected by test_threading
diff -r bd556f748cf8 Misc/NEWS
--- a/Misc/NEWS Sat Jul 23 03:39:49 2016 +0000
+++ b/Misc/NEWS Sat Jul 23 04:08:03 2016 +0000
@@ -38,7 +38,8 @@
- Issue #27567: Expose the EPOLLRDHUP and POLLRDHUP constants in the select
module.
-- Issue #1621: Avoid signed int negation overflow in the "audioop" module.
+- Issue #1621: Avoid signed integer overflow in the "audioop" and "_thread"
+ modules.
- Issue #27533: Release GIL in nt._isdir
diff -r bd556f748cf8 Modules/_threadmodule.c
--- a/Modules/_threadmodule.c Sat Jul 23 03:39:49 2016 +0000
+++ b/Modules/_threadmodule.c Sat Jul 23 04:08:03 2016 +0000
@@ -52,11 +52,12 @@
acquire_timed(PyThread_type_lock lock, _PyTime_t timeout)
{
PyLockStatus r;
- _PyTime_t endtime = 0;
+ _PyTime_t starttime = 0; /* Always initialized to suppress warning */
_PyTime_t microseconds;
- if (timeout > 0)
- endtime = _PyTime_GetMonotonicClock() + timeout;
+ if (timeout > 0) {
+ starttime = _PyTime_GetMonotonicClock();
+ }
do {
microseconds = _PyTime_AsMicroseconds(timeout, _PyTime_ROUND_CEILING);
@@ -80,13 +81,17 @@
/* If we're using a timeout, recompute the timeout after processing
* signals, since those can take time. */
if (timeout > 0) {
- timeout = endtime - _PyTime_GetMonotonicClock();
+ _PyTime_t elapsed = _PyTime_GetMonotonicClock() - starttime;
/* Check for negative values, since those mean block forever.
*/
- if (timeout < 0) {
+ if (timeout < elapsed) {
r = PY_LOCK_FAILURE;
}
+ else {
+ timeout -= elapsed;
+ starttime += elapsed;
+ }
}
}
} while (r == PY_LOCK_INTR); /* Retry if we were interrupted. */