Skip to content
This repository
Browse code

Fix for 64-bit ints

  • Loading branch information...
commit ccdd9e594f2eab7e7e804e0dc9244bb68facc39b 1 parent 1d94ebe
Michał Derkacz authored October 10, 2012

Showing 1 changed file with 6 additions and 6 deletions. Show diff stats Hide diff stats

  1. 12  mysql/row.go
12  mysql/row.go
@@ -52,7 +52,7 @@ func (tr Row) Str(nn int) (str string) {
52 52
 	return
53 53
 }
54 54
 
55  
-const _MAX_INT = int(^uint(0) >> 1)
  55
+const _MAX_INT = int64(int(^uint(0) >> 1))
56 56
 const _MIN_INT = -_MAX_INT - 1
57 57
 
58 58
 // Get the nn-th value and return it as int (0 if NULL). Return error if
@@ -74,13 +74,13 @@ func (tr Row) IntErr(nn int) (val int, err error) {
74 74
 	case []byte:
75 75
 		val, err = strconv.Atoi(string(data))
76 76
 	case int64:
77  
-		if data >= int64(_MIN_INT) && data <= int64(_MAX_INT) {
  77
+		if data >= _MIN_INT && data <= _MAX_INT {
78 78
 			val = int(data)
79 79
 		} else {
80 80
 			err = strconv.ErrRange
81 81
 		}
82 82
 	case uint32:
83  
-		if data <= uint32(_MAX_INT) {
  83
+		if int64(data) <= _MAX_INT {
84 84
 			val = int(data)
85 85
 		} else {
86 86
 			err = strconv.ErrRange
@@ -114,7 +114,7 @@ func (tr Row) ForceInt(nn int) (val int) {
114 114
 	return
115 115
 }
116 116
 
117  
-const _MAX_UINT = ^uint(0)
  117
+const _MAX_UINT = uint64(^uint(0))
118 118
 
119 119
 // Get the nn-th value and return it as uint (0 if NULL). Return error if
120 120
 // conversion is impossible.
@@ -133,14 +133,14 @@ func (tr Row) UintErr(nn int) (val uint, err error) {
133 133
 		v, err = strconv.ParseUint(string(data), 0, 0)
134 134
 		val = uint(v)
135 135
 	case uint64:
136  
-		if data <= uint64(_MAX_UINT) {
  136
+		if data <= _MAX_UINT {
137 137
 			val = uint(data)
138 138
 		} else {
139 139
 			err = strconv.ErrRange
140 140
 		}
141 141
 	case int8, int16, int32, int64:
142 142
 		v := reflect.ValueOf(data).Int()
143  
-		if v >= 0 && v <= int64(_MAX_UINT) {
  143
+		if v >= 0 && uint64(v) <= _MAX_UINT {
144 144
 			val = uint(v)
145 145
 		} else {
146 146
 			err = strconv.ErrRange

0 notes on commit ccdd9e5

Please sign in to comment.
Something went wrong with that request. Please try again.