From daee58bececb6e6c72aaeed183fd0d37d9c45228 Mon Sep 17 00:00:00 2001 From: Dekedro Date: Sun, 24 May 2020 12:44:17 +0000 Subject: [PATCH] Fix out of range access when requesting last page with `list` Prevent command `list` from failing with out of range access error if number of entries is lower than maximum entry index for that page a.k.a. if `len(result) < page*max` --- commands.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/commands.go b/commands.go index e7201c5..4e4932d 100644 --- a/commands.go +++ b/commands.go @@ -609,7 +609,11 @@ func (handler *CommandHandler) CommandList(ce *CommandEvent) { } return } - result = result[(page-1)*max : page*max] + lastIndex := page*max + if lastIndex > len(result) { + lastIndex = len(result) + } + result = result[(page-1)*max : lastIndex] ce.Reply("### %s (page %d of %d)\n\n%s", typeName, page, pages, strings.Join(result, "\n")) }