Skip to content

Commit

Permalink
fix infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
iandri authored and knqyf263 committed Nov 15, 2024
1 parent 3ed183d commit 2c4b013
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,16 @@ func compare(v1, v2 string) int {
strings2 = append([]string{""}, strings2...)
}

for i := 0; ; i++ {
var index int
c1 := len(strings1)
c2 := len(strings2)
if c1 >= c2 {
index = c1
} else {
index = c2
}

for i := 0; i < index; i++ {
// Compare non-digit strings
diff := compareString(strings1.get(i), strings2.get(i))
if diff != 0 {
Expand All @@ -223,14 +232,25 @@ func compare(v1, v2 string) int {
return diff
}
}

return 0
}

func compareString(s1, s2 string) int {
if s1 == s2 {
return 0
}

for i := 0; ; i++ {
var index int
c1 := len(s1)
c2 := len(s2)
if c1 >= c2 {
index = c1
} else {
index = c2
}

for i := 0; i < index; i++ {
a := 0
if i < len(s1) {
a = order(rune(s1[i]))
Expand All @@ -245,7 +265,7 @@ func compareString(s1, s2 string) int {
return a - b
}
}

return 0
}

// order function returns the number corresponding to rune
Expand Down

0 comments on commit 2c4b013

Please sign in to comment.