Skip to content

Commit 5399994

Browse files
authored
Fix LengthEncodedInt returning the length of 1 for an empty slice (#609)
* Fix LengthEncodedInt returning the length of 1 for an empty slice
1 parent 5ee187d commit 5399994

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

mysql/mysql_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,9 @@ func (t *mysqlTestSuite) TestMysqlUUIDClone(c *check.C) {
223223
clone := us.Clone()
224224
c.Assert(clone.String(), check.Equals, "de278ad0-2106-11e4-9f8e-6edd0ca20947:1-2")
225225
}
226+
227+
func (t *mysqlTestSuite) TestMysqlEmptyDecode(c *check.C) {
228+
_, isNull, n := LengthEncodedInt(nil)
229+
c.Assert(isNull, check.IsTrue)
230+
c.Assert(n, check.Equals, 0)
231+
}

mysql/util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func BFixedLengthInt(buf []byte) uint64 {
142142

143143
func LengthEncodedInt(b []byte) (num uint64, isNull bool, n int) {
144144
if len(b) == 0 {
145-
return 0, true, 1
145+
return 0, true, 0
146146
}
147147

148148
switch b[0] {

0 commit comments

Comments
 (0)