Skip to content

panic: runtime error: slice bounds out of range #127

Closed
@iambus

Description

@iambus
func TestPatchMakeOutOfRangePanic(t *testing.T) {
	text1 := `
  1111111111111 000000
  ------------- ------
  xxxxxxxxxxxxx ------
  xxxxxxxxxxxxx ------
  xxxxxxxxxxxxx xxxxxx
  xxxxxxxxxxxxx ......
  xxxxxxxxxxxxx 111111
  xxxxxxxxxxxxx ??????
  xxxxxxxxxxxxx 333333
  xxxxxxxxxxxxx 555555
  xxxxxxxxxx xxxxx
  xxxxxxxxxx xxxxx
  xxxxxxxxxx xxxxx
  xxxxxxxxxx xxxxx
`
	text2 := `
  2222222222222 000000
  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
	dmp := New()
	patches := dmp.PatchMake(text1, text2)
	assert.Equal(t, 6, len(patches), "aa")
}`
=== RUN   TestPatchMakeOutOfRangePanic
--- FAIL: TestPatchMakeOutOfRangePanic (0.00s)

panic: runtime error: slice bounds out of range [103:100] [recovered]
	panic: runtime error: slice bounds out of range [103:100]

goroutine 19 [running]:
testing.tRunner.func1.2({0x1d6020, 0xc0000a2738})
	/usr/go1.17/src/testing/testing.go:1209 +0x24e
testing.tRunner.func1()
	/usr/go1.17/src/testing/testing.go:1212 +0x218
panic({0x1d6020, 0xc0000a2738})
	/usr/go1.17/src/runtime/panic.go:1038 +0x215
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).patchMake2(0xc000093ed0, {0x1f6c06, 0x0}, {0xc00011c500, 0x8, 0x10})

	/go-diff/diffmatchpatch/patch.go:171 +0xa69
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).PatchMake(0xc000093ed0, {0xc000093e38, 0xb, 0x1a})
	/diffmatchpatch/patch.go:131 +0x1bc
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).PatchMake(0xe6393, {0xc000049f40, 0x24e39b, 0xf})
	/go-diff/diffmatchpatch/patch.go:129 +0x33b
github.com/sergi/go-diff/diffmatchpatch.TestPatchMakeOutOfRangePanic(0x0)
	/go-diff/diffmatchpatch/patch_test.go:362 +0x12a
testing.tRunner(0xc000085ba0, 0x1fc6b0)
	/usr/go1.17/src/testing/testing.go:1259 +0x102
created by testing.(*T).Run
	/usr/go1.17/src/testing/testing.go:1306 +0x35a


Process finished with the exit code 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions