Skip to content

Commit

Permalink
util: fix staticcheck errors (pingcap#13456)
Browse files Browse the repository at this point in the history
  • Loading branch information
someblue committed Nov 21, 2019
1 parent 92e7749 commit fd7fdb8
Show file tree
Hide file tree
Showing 14 changed files with 14 additions and 28 deletions.
12 changes: 6 additions & 6 deletions util/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,12 +754,12 @@ func iterRecords(sessCtx sessionctx.Context, retriever kv.Retriever, t table.Tab

// admin error codes.
const (
codeDataNotEqual terror.ErrCode = 1
codeRepeatHandle = 2
codeInvalidColumnState = 3
codeDDLJobNotFound = 4
codeCancelFinishedJob = 5
codeCannotCancelDDLJob = 6
codeDataNotEqual terror.ErrCode = iota + 1
codeRepeatHandle
codeInvalidColumnState
codeDDLJobNotFound
codeCancelFinishedJob
codeCannotCancelDDLJob
)

var (
Expand Down
1 change: 0 additions & 1 deletion util/chunk/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ func (l *List) Add(chk *Chunk) {
l.consumedIdx++
l.chunks = append(l.chunks, chk)
l.length += chk.NumRows()
return
}

func (l *List) allocChunk() (chk *Chunk) {
Expand Down
3 changes: 1 addition & 2 deletions util/codec/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ const (
)

var (
pads = make([]byte, encGroupSize)
encPads = []byte{encPad}
pads = make([]byte, encGroupSize)
)

// EncodeBytes guarantees the encoded value is in ascending order for comparison,
Expand Down
1 change: 0 additions & 1 deletion util/encrypt/aes.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func (x *ecbEncrypter) CryptBlocks(dst, src []byte) {
src = src[x.blockSize:]
dst = dst[x.blockSize:]
}
return
}

// newECBEncrypter creates an AES encrypter with ecb mode.
Expand Down
5 changes: 0 additions & 5 deletions util/encrypt/crypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ func (sc *sqlCrypt) init(password []byte, length int) {
sc.shift = 0
}

func (sc *sqlCrypt) reinit() {
sc.shift = 0
sc.rand = sc.orgRand
}

func (sc *sqlCrypt) encode(str []byte, length int) {
for i := 0; i < length; i++ {
sc.shift ^= uint32(sc.rand.myRand() * 255.0)
Expand Down
2 changes: 0 additions & 2 deletions util/expensivequery/expensivequery.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"fmt"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"

Expand All @@ -31,7 +30,6 @@ import (

// Handle is the handler for expensive query.
type Handle struct {
mu sync.RWMutex
exitCh chan struct{}
sm util.SessionManager
}
Expand Down
1 change: 0 additions & 1 deletion util/filesort/filesort.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,4 @@ func (w *Worker) flushToFile() {
w.ctx.appendFileName(fileName)
w.buf = w.buf[:0]
atomic.StoreInt32(&(w.busy), int32(0))
return
}
4 changes: 2 additions & 2 deletions util/kvcache/simple_lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type SimpleLRUCache struct {
// NewSimpleLRUCache creates a SimpleLRUCache object, whose capacity is "capacity".
// NOTE: "capacity" should be a positive value.
func NewSimpleLRUCache(capacity uint, guard float64, quota uint64) *SimpleLRUCache {
if capacity <= 0 {
if capacity == 0 {
panic("capacity of LRU Cache should be positive.")
}
return &SimpleLRUCache{
Expand Down Expand Up @@ -90,7 +90,7 @@ func (l *SimpleLRUCache) Put(key Key, value Value) {
l.size++

// Getting used memory is expensive and can be avoided by setting quota to 0.
if l.quota <= 0 {
if l.quota == 0 {
if l.size > l.capacity {
lru := l.cache.Back()
l.cache.Remove(lru)
Expand Down
2 changes: 0 additions & 2 deletions util/mock/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package mock
import (
"context"
"fmt"
"sync"
"time"

"github.com/pingcap/errors"
Expand All @@ -43,7 +42,6 @@ type Context struct {
txn wrapTxn // mock global variable
Store kv.Storage // mock global variable
sessionVars *variable.SessionVars
mux sync.Mutex // fix data race in ddl test.
ctx context.Context
cancel context.CancelFunc
sm util.SessionManager
Expand Down
2 changes: 1 addition & 1 deletion util/mvmap/fnv.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package mvmap

const (
offset64 uint64 = 14695981039346656037
prime64 = 1099511628211
prime64 uint64 = 1099511628211
)

// fnvHash64 is ported from go library, which is thread-safe.
Expand Down
2 changes: 1 addition & 1 deletion util/plancodec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func decodePlanInfo(str string) (*planInfo, error) {
return nil, errors.Errorf("decode plan: %v error, invalid plan id: %v", str, v)
}
planID, err := strconv.Atoi(ids[0])
if err != err {
if err != nil {
return nil, errors.Errorf("decode plan: %v, plan id: %v, error: %v", str, v, err)
}
p.fields = append(p.fields, PhysicalIDToTypeString(planID)+idSeparator+ids[1])
Expand Down
1 change: 0 additions & 1 deletion util/rowcodec/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type Encoder struct {
row
tempColIDs []int64
values []types.Datum
tempData []byte
sc *stmtctx.StatementContext
}

Expand Down
2 changes: 1 addition & 1 deletion util/stringutil/string_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s *testStringUtilSuite) TestUnquote(c *C) {
{`' '`, ` `, true},
{"'\\a汉字'", "a汉字", true},
{"'\\a\x90'", "a\x90", true},
{`"\aèàø»"`, `aèàø»`, true},
{"\"\\a\x18èàø»\x05\"", "a\x18èàø»\x05", true},
}

for _, t := range table {
Expand Down
4 changes: 2 additions & 2 deletions util/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func LoadTestSuiteData(dir, suiteName string) (res TestData, err error) {
return res, err
}
if record {
res.output = make([]testCases, len(res.input), len(res.input))
res.output = make([]testCases, len(res.input))
for i := range res.input {
res.output[i].Name = res.input[i].Name
}
Expand Down Expand Up @@ -273,7 +273,7 @@ func (t *TestData) GenerateOutputIfNeeded() error {
if err != nil {
return err
}
res := make([]byte, len(buf.Bytes()), len(buf.Bytes()))
res := make([]byte, len(buf.Bytes()))
copy(res, buf.Bytes())
buf.Reset()
rm := json.RawMessage(res)
Expand Down

0 comments on commit fd7fdb8

Please sign in to comment.