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 <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Tim Culverhouse 2022-07-05 15:36:29 -05:00 committed by Robin Jarry
parent e19b411e52
commit 635530b12d
1 changed files with 1 additions and 3 deletions

View File

@ -403,9 +403,7 @@ func (ml *MessageList) Empty() bool {
} }
func (ml *MessageList) Selected() *models.MessageInfo { func (ml *MessageList) Selected() *models.MessageInfo {
store := ml.Store() return ml.Store().Selected()
uids := store.Uids()
return store.Messages[uids[len(uids)-ml.store.SelectedIndex()-1]]
} }
func (ml *MessageList) Select(index int) { func (ml *MessageList) Select(index int) {