diff --git a/version.go b/version.go index 1d80412..a01b2e4 100644 --- a/version.go +++ b/version.go @@ -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 { @@ -223,6 +232,8 @@ func compare(v1, v2 string) int { return diff } } + + return 0 } func compareString(s1, s2 string) int { @@ -230,7 +241,16 @@ func compareString(s1, s2 string) int { 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])) @@ -245,7 +265,7 @@ func compareString(s1, s2 string) int { return a - b } } - + return 0 } // order function returns the number corresponding to rune diff --git a/version_test.go b/version_test.go index 1288140..b592552 100644 --- a/version_test.go +++ b/version_test.go @@ -111,6 +111,7 @@ func TestEqual(t *testing.T) { {Version{2, "7.4.052", "1ubuntu3"}, Version{2, "7.4.052", "1ubuntu3"}, true}, {Version{2, "7.4.052", "1ubuntu1"}, Version{2, "7.4.052", "1"}, false}, {Version{upstreamVersion: "7.4.052"}, Version{upstreamVersion: "7.4.052"}, true}, + {Version{upstreamVersion: "3.12", debianRevision: "1+deb9u1build0.16.4.1"}, Version{upstreamVersion: "3.12", debianRevision: "1+deb9u1build0.16.04.1"}, true}, } for _, tc := range cases { actual := tc.v1.Equal(tc.v2)