D9279: pure: guard against empty blocks

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Sun Nov 8 01:23:08 UTC 2020


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

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
 
 



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


More information about the Mercurial-devel mailing list