Skip to content

Commit

Permalink
lint: Fix SA1019 Using a deprecated function
Browse files Browse the repository at this point in the history
`rand.Read` has been deprecated since Go 1.20
`crypto/rand.Read` is more appropriate

Ref: https://tip.golang.org/doc/go1.20

Signed-off-by: Michal Biesek <michalbiesek@gmail.com>
  • Loading branch information
michalbiesek committed Aug 25, 2023
1 parent 7d1110a commit 04d7b4d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions tsdb/wlog/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ package wlog

import (
"bytes"
"crypto/rand"
"encoding/binary"
"fmt"
"hash/crc32"
"io"
"math/rand"
"math/big"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -252,8 +253,11 @@ func generateRandomEntries(w *WL, records chan []byte) error {
default:
sz = pageSize * 8
}

rec := make([]byte, rand.Int63n(sz))
n, err := rand.Int(rand.Reader, big.NewInt(sz))
if err != nil {
return err
}
rec := make([]byte, n.Int64())
if _, err := rand.Read(rec); err != nil {
return err
}
Expand All @@ -262,7 +266,11 @@ func generateRandomEntries(w *WL, records chan []byte) error {

// Randomly batch up records.
recs = append(recs, rec)
if rand.Intn(4) < 3 {
n, err = rand.Int(rand.Reader, big.NewInt(int64(4)))
if err != nil {
return err
}
if int(n.Int64()) < 3 {
if err := w.Log(recs...); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion tsdb/wlog/wlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ package wlog

import (
"bytes"
"crypto/rand"
"fmt"
"io"
"math/rand"
"os"
"path/filepath"
"testing"
Expand Down

0 comments on commit 04d7b4d

Please sign in to comment.