Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: runtime error: index out of range #3

Closed
stevemeier opened this issue Jul 14, 2019 · 3 comments
Closed

panic: runtime error: index out of range #3

stevemeier opened this issue Jul 14, 2019 · 3 comments

Comments

@stevemeier
Copy link

Hello,

please excuse if this is not an issue with your code but as a beginner in Golang it seems to me like it could be.

Here is the sample code I run:

package main

import "fmt"
import "github.com/davecgh/go-spew/spew"
import "github.com/agext/levenshtein"

func main () {
	var myparams = levenshtein.NewParams()
	myparams.MinScore(0.92)
	spew.Dump(myparams)

	fmt.Println(levenshtein.Match(`foo`, `foo`, myparams))
	fmt.Println(levenshtein.Match(`foo`, `bar`, myparams))
	fmt.Println(levenshtein.Match(`NetworkManager-glib-0.8.1-5.el6_0.1.i686.rpm`, `gdm-plugin-fingerprint-2.30.4-39.el6.i686.rpm`, myparams))
}

It produces the following output:

(*levenshtein.Params)(0xc000094100)({
 insCost: (int) 1,
 subCost: (int) 1,
 delCost: (int) 1,
 maxCost: (int) 0,
 minScore: (float64) 0.92,
 bonusPrefix: (int) 4,
 bonusScale: (float64) 0.1,
 bonusThreshold: (float64) 0.7
})
1
0
panic: runtime error: index out of range

goroutine 1 [running]:
github.com/agext/levenshtein.Calculate(0xc0000ca000, 0x24, 0x2c, 0xc0000cc000, 0x23, 0x30, 0x5, 0x1, 0x1, 0x1, ...)
	/Users/smeier/go/src/github.com/agext/levenshtein/levenshtein.go:112 +0x8ba
github.com/agext/levenshtein.Match(0x11036f6, 0x2c, 0x11037ff, 0x2d, 0xc000094100, 0x2)
	/Users/smeier/go/src/github.com/agext/levenshtein/levenshtein.go:272 +0x1a8
main.main()
	/Users/smeier/Documents/grabbag/levenshtein_bug.go:14 +0x271
exit status 2

I am running go version go1.12.5 darwin/amd64.

Any help or comments are appreciated.

@alex-alrux
Copy link
Member

Hi Steve,

Thanks for finding and reporting this - it does look like a bug. We'll look into it right away and should have a fix within the next couple of days.

@alex-alrux
Copy link
Member

Just pushed a fix. I will leave the issue open for now, in case anyone has a related comment (e.g. issue still occurring for them). If no new activity, I will close it in a few days and cut a new patch-version release.

@stevemeier
Copy link
Author

Looks good. My full script (not the snippet in the report) no longer crashes and the run-time with MinScore set is now roughly 25% less. Thanks for this quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants