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

fix infinite loop #5

Merged
merged 2 commits into from
Nov 15, 2024
Merged

fix infinite loop #5

merged 2 commits into from
Nov 15, 2024

Conversation

iandri
Copy link
Contributor

@iandri iandri commented Mar 7, 2022

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@knqyf263
Copy link
Owner

Could you give me an example to reproduce the issue?

@iandri
Copy link
Contributor Author

iandri commented Mar 10, 2022 via email

Copy link
Owner

@knqyf263 knqyf263 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late reply. Could you add a test case to replicate this issue?

Comment on lines +201 to +220
var index int
c1 := len(strings1)
c2 := len(strings2)
if c1 >= c2 {
index = c1
} else {
index = c2
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if comparing numbers1 with numbers2, and strings1 with strings2?

Suggested change
var index int
c1 := len(strings1)
c2 := len(strings2)
if c1 >= c2 {
index = c1
} else {
index = c2
}
if reflect.DeepEqual(numbers1, numbers2) && reflect.DeepEqual(strings1, strings2) {
return 0
}

Comment on lines +232 to +253
var index int
c1 := len(s1)
c2 := len(s2)
if c1 >= c2 {
index = c1
} else {
index = c2
}

for i := 0; i < index; i++ {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure we need them? if s1 == s2 {} prevents infinite loops, I think.

@deven0t
Copy link

deven0t commented Nov 15, 2024

Hi @knqyf263
Adding one more example for infinite loop
"3.12-1+deb9u1build0.16.4.1",
"3.12-1+deb9u1build0.16.04.1"

code: https://go.dev/play/p/lxgVQJPtpw3

@knqyf263 knqyf263 merged commit 61cdcc2 into knqyf263:master Nov 15, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

3 participants