Skip to content

Commit 6e0ddbf

Browse files
authored
Merge pull request #708 from LPX3F8/lpx3f8/220629_optim_remove_useless_code
optim: remove useless return value for mysql.util.RandomBuf
2 parents becd1ef + 5638f15 commit 6e0ddbf

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

mysql/util.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ func AppendLengthEncodedInteger(b []byte, n uint64) []byte {
107107
byte(n>>32), byte(n>>40), byte(n>>48), byte(n>>56))
108108
}
109109

110-
func RandomBuf(size int) ([]byte, error) {
110+
func RandomBuf(size int) []byte {
111111
buf := make([]byte, size)
112112
mrand.Seed(time.Now().UTC().UnixNano())
113113
min, max := 30, 127
114114
for i := 0; i < size; i++ {
115115
buf[i] = byte(min + mrand.Intn(max-min))
116116
}
117-
return buf, nil
117+
return buf
118118
}
119119

120120
// FixedLengthInt: little endian

server/conn.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import (
55
"net"
66
"sync/atomic"
77

8+
"github.com/siddontang/go/sync2"
9+
810
. "github.com/go-mysql-org/go-mysql/mysql"
911
"github.com/go-mysql-org/go-mysql/packet"
10-
"github.com/siddontang/go/sync2"
1112
)
1213

1314
/*
@@ -45,7 +46,6 @@ var baseConnID uint32 = 10000
4546
func NewConn(conn net.Conn, user string, password string, h Handler) (*Conn, error) {
4647
p := NewInMemoryProvider()
4748
p.AddUser(user, password)
48-
salt, _ := RandomBuf(20)
4949

5050
var packetConn *packet.Conn
5151
if defaultServer.tlsConfig != nil {
@@ -61,7 +61,7 @@ func NewConn(conn net.Conn, user string, password string, h Handler) (*Conn, err
6161
h: h,
6262
connectionID: atomic.AddUint32(&baseConnID, 1),
6363
stmts: make(map[uint32]*Stmt),
64-
salt: salt,
64+
salt: RandomBuf(20),
6565
}
6666
c.closed.Set(false)
6767

@@ -82,15 +82,14 @@ func NewCustomizedConn(conn net.Conn, serverConf *Server, p CredentialProvider,
8282
packetConn = packet.NewConn(conn)
8383
}
8484

85-
salt, _ := RandomBuf(20)
8685
c := &Conn{
8786
Conn: packetConn,
8887
serverConf: serverConf,
8988
credentialProvider: p,
9089
h: h,
9190
connectionID: atomic.AddUint32(&baseConnID, 1),
9291
stmts: make(map[uint32]*Stmt),
93-
salt: salt,
92+
salt: RandomBuf(20),
9493
}
9594
c.closed.Set(false)
9695

server/resp.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,8 @@ func (c *Conn) writeAuthSwitchRequest(newAuthPluginName string) error {
6868
data = append(data, EOF_HEADER)
6969
data = append(data, []byte(newAuthPluginName)...)
7070
data = append(data, 0x00)
71-
rnd, err := RandomBuf(20)
72-
if err != nil {
73-
return err
74-
}
7571
// new auth data
76-
c.salt = rnd
72+
c.salt = RandomBuf(20)
7773
data = append(data, c.salt...)
7874
// the online doc states it's a string.EOF, however, the actual MySQL server add a \NUL to the end, without it, the
7975
// official MySQL client will fail.

0 commit comments

Comments
 (0)