From 635530b12d46ff29555ba322a6bfd3c5bf8f4e7a Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 5 Jul 2022 15:36:29 -0500 Subject: msglist: fix panic for index-out-of-range I didn't save the stack trace, but msglist.Selected() can create a panic for index out of range due to the math operations in the map. My stack trace resulted in a [-9]. This patch reuses the msgstore.Selected() method, which already has bounds checking. Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- widgets/msglist.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/widgets/msglist.go b/widgets/msglist.go index ec14e79..399ed72 100644 --- a/widgets/msglist.go +++ b/widgets/msglist.go @@ -403,9 +403,7 @@ func (ml *MessageList) Empty() bool { } func (ml *MessageList) Selected() *models.MessageInfo { - store := ml.Store() - uids := store.Uids() - return store.Messages[uids[len(uids)-ml.store.SelectedIndex()-1]] + return ml.Store().Selected() } func (ml *MessageList) Select(index int) { -- cgit v1.2.3