]> xenbits.xensource.com Git - people/gdunlap/xsatool/commitdiff
xen: Use MaxInt32 rather than MaxInt64 for internal version of 'master'
authorGeorge Dunlap <george.dunlap@citrix.com>
Fri, 8 Dec 2017 12:27:14 +0000 (12:27 +0000)
committerGeorge Dunlap <george.dunlap@citrix.com>
Fri, 8 Dec 2017 12:27:14 +0000 (12:27 +0000)
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 <george.dunlap@citrix.com>
xen.go

diff --git a/xen.go b/xen.go
index e14694970151e95276ddc233c405ff7e3c63fcaa..ff4c2c404515d5995d83ccdbebfb75ba43b64a99 100644 (file)
--- 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)