-
Notifications
You must be signed in to change notification settings - Fork 219
Closed
Labels
Description
I've encountered this issue while using https://github.com/src-d/go-git, but the bug is easily reproducible with the code snippet below and the JSON file in attachment.
package main
import (
"fmt"
"io/ioutil"
"os"
"github.com/sergi/go-diff/diffmatchpatch"
)
func main() {
f, err := os.Open("data.txt")
defer f.Close()
checkErr(err)
data, err := ioutil.ReadAll(f)
checkErr(err)
// from https://github.com/src-d/go-git/blob/v4.0.0/utils/diff/diff.go#L17
dmp := diffmatchpatch.New()
wSrc, wDst, warray := dmp.DiffLinesToChars(string(data), "")
diffs := dmp.DiffMain(wSrc, wDst, false)
diffs = dmp.DiffCharsToLines(diffs, warray)
fmt.Println(diffs)
}
func checkErr(err error) {
if err != nil {
panic(err)
}
}
Output:
$ go run main.go
panic: runtime error: index out of range
goroutine 1 [running]:
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).DiffCharsToLines(0xc420044ee8, 0xc420078390, 0x1, 0x2, 0xc4202ce000, 0xd802, 0xec00, 0x1, 0x2, 0xc4202ce000)
/Users/krylovsk/src/github.com/sergi/go-diff/diffmatchpatch/diff.go:414 +0x394
main.main()
/tmp/go-diff-debug/main.go:24 +0x29e
exit status 2