From 3450ea89e0394843492b0bc05c4c08e9ea8c8815 Mon Sep 17 00:00:00 2001 From: Seednode Date: Sat, 29 Oct 2022 10:41:03 -0500 Subject: [PATCH] Fixed for loop requesting out-of-range index in pickFile() --- cmd/files.go | 8 +++++--- cmd/version.go | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/files.go b/cmd/files.go index 2fa0cc1..1748cc6 100644 --- a/cmd/files.go +++ b/cmd/files.go @@ -496,12 +496,12 @@ func pickFile(args []string, filters *Filters, sort string, fileCache *[]string) } } - fileCount := len(fileList) - 1 + fileCount := len(fileList) - r := rand.Intn(fileCount) + r := rand.Intn(fileCount - 1) for i := 0; i < fileCount; i++ { - if r > fileCount { + if r >= (fileCount - 1) { r = 0 } else { r++ @@ -518,6 +518,8 @@ func pickFile(args []string, filters *Filters, sort string, fileCache *[]string) if isImage { return filePath, nil } + + continue } return filePath, nil diff --git a/cmd/version.go b/cmd/version.go index 6b0e656..828856d 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" ) -var Version = "0.20.8" +var Version = "0.20.9" func init() { rootCmd.AddCommand(versionCmd)