Patchwork [1,of,3,STABLE] diffhelpers: backport 9e40bc4c1bde from C implementation

login
register
mail settings
Submitter Yuya Nishihara
Date April 20, 2018, 12:10 p.m.
Message ID <171c91d2e6fb2ce686d2.1524226232@mimosa>
Download mbox | patch
Permalink /patch/31204/
State Accepted
Headers show

Comments

Yuya Nishihara - April 20, 2018, 12:10 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1524148397 -32400
#      Thu Apr 19 23:33:17 2018 +0900
# Branch stable
# Node ID 171c91d2e6fb2ce686d24b34da5cc81482e0223d
# Parent  62053dbefda333714d285dbd2274067864186e19
diffhelpers: backport 9e40bc4c1bde from C implementation

9e40bc4c1bde just says "harden testhunk." I don't think this would be
the case, but it makes some sense to avoid negative index.

Patch

diff --git a/mercurial/diffhelpers.py b/mercurial/diffhelpers.py
--- a/mercurial/diffhelpers.py
+++ b/mercurial/diffhelpers.py
@@ -69,7 +69,7 @@  def testhunk(a, b, bstart):
     """
     alen = len(a)
     blen = len(b)
-    if alen > blen - bstart:
+    if alen > blen - bstart or bstart < 0:
         return False
     for i in xrange(alen):
         if a[i][1:] != b[i + bstart]: