From: Benjamin Peterson Date: Wed, 25 Feb 2015 15:12:26 +0000 (-0500) Subject: fix merge_collapse to actually maintain the invariant it purports to (closes #23515) X-Git-Tag: v3.5.0a2~90^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b808d590a24066bc03d21b55ed5e890a012477a8;p=python 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" --- diff --git a/Objects/listobject.c b/Objects/listobject.c index fd5a72af8d..b6c1d784fb 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)