Skip to content

Commit

Permalink
fix infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
iandri committed Mar 7, 2022
1 parent 09fca49 commit 6fac357
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 @@ -198,7 +198,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 @@ -211,14 +220,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 @@ -233,7 +253,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 6fac357

Please sign in to comment.