From 007ebc477a9cb14704cf628859e9de747c268d5b Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Wed, 14 Feb 2018 18:14:15 +0100 Subject: fix crash when generating a unified diff with a small ending equal-chunk Signed-off-by: Mechiel Lukkien --- plumbing/format/diff/unified_encoder.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'plumbing') diff --git a/plumbing/format/diff/unified_encoder.go b/plumbing/format/diff/unified_encoder.go index cf2a34b..58edd95 100644 --- a/plumbing/format/diff/unified_encoder.go +++ b/plumbing/format/diff/unified_encoder.go @@ -262,11 +262,15 @@ func (c *hunksGenerator) processEqualsLines(ls []string, i int) { c.current.AddOp(Equal, c.afterContext...) c.afterContext = nil } else { - c.current.AddOp(Equal, c.afterContext[:c.ctxLines]...) + ctxLines := c.ctxLines + if ctxLines > len(c.afterContext) { + ctxLines = len(c.afterContext) + } + c.current.AddOp(Equal, c.afterContext[:ctxLines]...) c.hunks = append(c.hunks, c.current) c.current = nil - c.beforeContext = c.afterContext[c.ctxLines:] + c.beforeContext = c.afterContext[ctxLines:] c.afterContext = nil } } -- cgit