Skip to content

Commit 7cdb222

Browse files
authored
Merge pull request #18 from vvoland/fix-selection
cmd/linkwinbt: Fix user selection validation
2 parents c46f4c8 + b22b6bf commit 7cdb222

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

cmd/linkwinbt/main.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,14 @@ func getUserSelection(prompt string, itemCount int) (int, error) {
166166
return -1, errors.New("selection canceled")
167167
}
168168

169-
idx, err := strconv.Atoi(input)
170-
if err != nil || idx < 1 || idx > itemCount {
171-
return -1, fmt.Errorf("invalid selection: %s", input)
169+
num, err := strconv.Atoi(input)
170+
if err != nil {
171+
return -1, fmt.Errorf("invalid selection: not an integer: %s", input)
172+
}
173+
174+
if num < 0 || num >= itemCount {
175+
return -1, fmt.Errorf("selection (%d) out of range, allowed range is 0-%d", num, itemCount)
172176
}
173177

174-
return idx, nil
178+
return num, nil
175179
}

0 commit comments

Comments
 (0)