diff options
author | Mechiel Lukkien <mechiel@ueber.net> | 2018-02-14 18:14:15 +0100 |
---|---|---|
committer | Mechiel Lukkien <mechiel@ueber.net> | 2018-02-14 18:14:15 +0100 |
commit | 007ebc477a9cb14704cf628859e9de747c268d5b (patch) | |
tree | 38b9bb2b722aca8a87291e459fd22e59e81f8a52 /plumbing | |
parent | 01c428c50c89c47e40dfdd4ecf43376cf48e1797 (diff) | |
download | go-git-007ebc477a9cb14704cf628859e9de747c268d5b.tar.gz |
fix crash when generating a unified diff with a small ending equal-chunk
Signed-off-by: Mechiel Lukkien <mechiel@ueber.net>
Diffstat (limited to 'plumbing')
-rw-r--r-- | plumbing/format/diff/unified_encoder.go | 8 |
1 files changed, 6 insertions, 2 deletions
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 } } |