summaryrefslogtreecommitdiffstats
path: root/Objects/listobject.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2015-02-25 15:12:26 (GMT)
committerBenjamin Peterson <benjamin@python.org>2015-02-25 15:12:26 (GMT)
commitb808d590a24066bc03d21b55ed5e890a012477a8 (patch)
treed71618159fa185eda5ec63e6d93e2f63761971c0 /Objects/listobject.c
parent83704963c0d4e7b1474d6102ed6287a7ae4907a8 (diff)
downloadcpython-b808d590a24066bc03d21b55ed5e890a012477a8.zip
cpython-b808d590a24066bc03d21b55ed5e890a012477a8.tar.gz
cpython-b808d590a24066bc03d21b55ed5e890a012477a8.tar.bz2
fix merge_collapse to actually maintain the invariant it purports to (closes #23515)
See de Gouw, Stijn and Rot, Jurriaan and de Boer, Frank S and Bubel, Richard and Hähnle, Reiner "OpenJDK’s java.utils.Collection.sort() is broken: The good, the bad and the worst case"
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r--Objects/listobject.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index fd5a72a..b6c1d78 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -1832,7 +1832,8 @@ merge_collapse(MergeState *ms)
assert(ms);
while (ms->n > 1) {
Py_ssize_t n = ms->n - 2;
- if (n > 0 && p[n-1].len <= p[n].len + p[n+1].len) {
+ if ((n > 0 && p[n-1].len <= p[n].len + p[n+1].len) ||
+ (n > 1 && p[n-2].len <= p[n-1].len + p[n].len)) {
if (p[n-1].len < p[n+1].len)
--n;
if (merge_at(ms, n) < 0)