Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 007ebc4

Browse files
committed
fix crash when generating a unified diff with a small ending equal-chunk
Signed-off-by: Mechiel Lukkien <[email protected]>
1 parent 01c428c commit 007ebc4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

plumbing/format/diff/unified_encoder.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,15 @@ func (c *hunksGenerator) processEqualsLines(ls []string, i int) {
262262
c.current.AddOp(Equal, c.afterContext...)
263263
c.afterContext = nil
264264
} else {
265-
c.current.AddOp(Equal, c.afterContext[:c.ctxLines]...)
265+
ctxLines := c.ctxLines
266+
if ctxLines > len(c.afterContext) {
267+
ctxLines = len(c.afterContext)
268+
}
269+
c.current.AddOp(Equal, c.afterContext[:ctxLines]...)
266270
c.hunks = append(c.hunks, c.current)
267271

268272
c.current = nil
269-
c.beforeContext = c.afterContext[c.ctxLines:]
273+
c.beforeContext = c.afterContext[ctxLines:]
270274
c.afterContext = nil
271275
}
272276
}

0 commit comments

Comments
 (0)