From 04d7b4dbee6076235295a00b1af62dd93ba1ca47 Mon Sep 17 00:00:00 2001 From: Michal Biesek Date: Mon, 14 Aug 2023 23:42:02 +0200 Subject: [PATCH] lint: Fix `SA1019` Using a deprecated function `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 --- tsdb/wlog/reader_test.go | 16 ++++++++++++---- tsdb/wlog/wlog_test.go | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tsdb/wlog/reader_test.go b/tsdb/wlog/reader_test.go index 2c4dd622c0..309bee755e 100644 --- a/tsdb/wlog/reader_test.go +++ b/tsdb/wlog/reader_test.go @@ -16,11 +16,12 @@ package wlog import ( "bytes" + "crypto/rand" "encoding/binary" "fmt" "hash/crc32" "io" - "math/rand" + "math/big" "os" "path/filepath" "runtime" @@ -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 } @@ -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 } diff --git a/tsdb/wlog/wlog_test.go b/tsdb/wlog/wlog_test.go index f9ce225b37..5602a3ee07 100644 --- a/tsdb/wlog/wlog_test.go +++ b/tsdb/wlog/wlog_test.go @@ -16,9 +16,9 @@ package wlog import ( "bytes" + "crypto/rand" "fmt" "io" - "math/rand" "os" "path/filepath" "testing"