From: George Dunlap Date: Fri, 8 Dec 2017 12:27:14 +0000 (+0000) Subject: xen: Use MaxInt32 rather than MaxInt64 for internal version of 'master' X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=02c0032ec33eaa47c8037867917afb0062b8522d;p=people%2Fgdunlap%2Fxsatool.git xen: Use MaxInt32 rather than MaxInt64 for internal version of 'master' We currently use MaxInt64 as the "version number" for 'master' internally so that 'master' always compares as "greater than" all normal Xen versions. Unfortunately, on 32-bit builds 'int' is only 32 bits, so building results in the following error: ./xen.go:22:3: constant 9223372036854775807 overflows int The 'math' package doesn't contain a MaxInt (which is why it was MaxInt64 in the first place); but MaxInt32 will be fit for purpose for both architectures. At such time as Xen's major number exceeds 2 billion, we can deprecate the 32-bit build of this tool. The other option would have been to use code from this template to calculate MaxInt at compile time: https://groups.google.com/forum/#!msg/golang-nuts/a9PitPAHSSU/ziQw1-QHw3EJ But I think that would have been a bit overkill. Signed-off-by: George Dunlap --- diff --git a/xen.go b/xen.go index e146949..ff4c2c4 100644 --- a/xen.go +++ b/xen.go @@ -19,7 +19,9 @@ func (v XenVersion) String() string { func (v XenVersion) parse() (major, minor int, err error) { if v == "master" { - return math.MaxInt64, 0, nil + // NB if Xen's major ever exceeds 2 billion, we'll + // need to deprecate the 32-bit build of this tool. + return math.MaxInt32, 0, nil } major = -1 @@ -33,9 +35,18 @@ func (v XenVersion) parse() (major, minor int, err error) { } major, err = strconv.Atoi(submatch[1]) - if err == nil { - minor, err = strconv.Atoi(submatch[2]) + if err != nil { + return } + + if major > math.MaxInt32 { + err = fmt.Errorf("Version too large") + major = -1 + return + } + + minor, err = strconv.Atoi(submatch[2]) + return } @@ -89,7 +100,7 @@ func (v XenVersion) IsGreaterThan(v2 XenVersion) bool { return v.gt(v2, false) } -func (v XenVersion) PrevVersion() (next XenVersion, err error) { +func (v XenVersion) PrevVersiongit () (next XenVersion, err error) { major, minor, err := v.parse() if err != nil { err = fmt.Errorf("Parsing version %v: %v\n", v, err)