Patchwork D9279: pure: guard against empty blocks

login
register
mail settings
Submitter phabricator
Date Nov. 8, 2020, 1:23 a.m.
Message ID <differential-rev-PHID-DREV-bsobe7rkts7kxzdhx5ee-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47554/
State Superseded
Headers show

Comments

phabricator - Nov. 8, 2020, 1:23 a.m.
indygreg created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  If blocks is empty, we append `None` to the returned list, which is
  incorrect.
  
  This subtle issue was caught by pytype, which correctly identified
  the return value as List[Optional[Tuple]] because of this possibility.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9279

AFFECTED FILES
  mercurial/pure/bdiff.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/pure/bdiff.py b/mercurial/pure/bdiff.py
--- a/mercurial/pure/bdiff.py
+++ b/mercurial/pure/bdiff.py
@@ -51,7 +51,10 @@ 
                 shift += 1
         r.append((a1, b1, l1 + shift))
         prev = a2 + shift, b2 + shift, l2 - shift
-    r.append(prev)
+
+    if prev is not None:
+        r.append(prev)
+
     return r