Fix out of bounds array access in acceptable-versions command

This commit is contained in:
comp500 2023-06-27 00:46:26 +01:00
parent e8c28ae57e
commit 41465407b2

View File

@ -104,7 +104,7 @@ var acceptableVersionsCommand = &cobra.Command{
// If it's only 1 element long, then it's already sorted // If it's only 1 element long, then it's already sorted
if len(acceptableVersionsDeduped) > 1 { if len(acceptableVersionsDeduped) > 1 {
for i, v := range acceptableVersionsDeduped { for i, v := range acceptableVersionsDeduped {
if flexver.Less(acceptableVersionsDeduped[i+1], v) { if i+1 < len(acceptableVersionsDeduped) && flexver.Less(acceptableVersionsDeduped[i+1], v) {
fmt.Printf("Warning: Your acceptable versions list is out of order. ") fmt.Printf("Warning: Your acceptable versions list is out of order. ")
// Give a do you mean example // Give a do you mean example
// Clone the list // Clone the list