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 in matches index #3

Open
idawson-gl opened this issue Oct 24, 2022 · 2 comments
Open

panic in matches index #3

idawson-gl opened this issue Oct 24, 2022 · 2 comments

Comments

@idawson-gl
Copy link

There is a panic when comparing the window runes with the matches slice if the strings.Index call returns an index greater than the number of matches.

		idx := strings.Index(string(slider), string(runes1[i]))
		if idx != -1 && !matches[idx] { // panic here
			t += 0.5
			matches[idx] = true
		}

I was able to reproduce this when comparing the two following strings:

jwd.Calculate("asdfadsfT", "Academic Free License v1.2")
...

goroutine 19 [running]:
testing.tRunner.func1.2({0x104db2d80, 0x14000126258})
	/opt/homebrew/Cellar/go/1.19.1/libexec/src/testing/testing.go:1396 +0x1c8
testing.tRunner.func1()
	/opt/homebrew/Cellar/go/1.19.1/libexec/src/testing/testing.go:1399 +0x378
panic({0x104db2d80, 0x14000126258})
	/opt/homebrew/Cellar/go/1.19.1/libexec/src/runtime/panic.go:884 +0x204
github.com/jhvst/go-jaro-winkler-distance.Calculate({0x104d16155?, 0x104d16ed8?}, {0x104d1c760, 0x1a})
	/Users/xxx/go/pkg/mod/github.com/jhvst/[email protected]/algo.go:58 +0x4c4
testing.tRunner(0x14000107040, 0x104dc3a28)

While this can be fixed with ensuring the length, I'm not entirely sure the logic of the strings.Index is correct, or how the matches slice is created is correct.

		idx := strings.Index(string(slider), string(runes1[i]))
		if idx != -1 && idx < len(matches) && !matches[idx] {
			t += 0.5
			matches[idx] = true
		}

Should the index really ever be returning a value that's greater than the number of matches?

@jhvst
Copy link
Owner

jhvst commented Oct 24, 2022

Hi Isaac, thanks for the bug report. I have to remind myself what the reference implementation was, and recheck the logic issue you raised here. It's likely that you are correct here, but let me find the time to take a plunge at the code and return back to this.

@dtracers
Copy link

dtracers commented Nov 3, 2023

Hi Has this issue been fixed?

I have run into this myself.

It looks like any strings that are less than size "window" or have fewer matches than size "window" will crash.

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

3 participants