From 76c1b1371b029b976b1336f540f0ceaac64f464b Mon Sep 17 00:00:00 2001 From: lalyos Date: Mon, 11 Aug 2014 23:40:35 +0200 Subject: [PATCH] Fix equal short-long version number comparison Signed-off-by: Lajos Papp --- version/version.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/version/version.go b/version/version.go index 5ff9d2e..6a7d635 100644 --- a/version/version.go +++ b/version/version.go @@ -12,9 +12,17 @@ func (me Version) compareTo(other Version) int { meTab = strings.Split(string(me), ".") otherTab = strings.Split(string(other), ".") ) - for i, s := range meTab { + + max := len(meTab) + if len(otherTab) > max { + max = len(otherTab) + } + for i := 0; i < max; i++ { var meInt, otherInt int - meInt, _ = strconv.Atoi(s) + + if len(meTab) > i { + meInt, _ = strconv.Atoi(meTab[i]) + } if len(otherTab) > i { otherInt, _ = strconv.Atoi(otherTab[i]) } @@ -25,9 +33,6 @@ func (me Version) compareTo(other Version) int { return -1 } } - if len(otherTab) > len(meTab) { - return -1 - } return 0 }