Fix crash when no message is selected

Pressing `Enter` on a view that has not yet loaded messages (e.g. at
startup) would return `nil` from `Selected()`. Accessing `msg.Uid` on a
`nil` reference crashes aerc.

This patch moves the `msg == nil` check before accessing `msg.Uid` thus
avoiding the crash.

To test this patch repeatedly press `Enter` on startup.
This commit is contained in:
Wiktor Kwapisiewicz 2019-11-28 19:20:45 +01:00 committed by Drew DeVault
parent 31e3e9f56e
commit abd9e78f02
1 changed files with 4 additions and 1 deletions

View File

@ -30,8 +30,11 @@ func (ViewMessage) Execute(aerc *widgets.Aerc, args []string) error {
} }
store := acct.Messages().Store() store := acct.Messages().Store()
msg := acct.Messages().Selected() msg := acct.Messages().Selected()
if msg == nil {
return nil
}
_, deleted := store.Deleted[msg.Uid] _, deleted := store.Deleted[msg.Uid]
if msg == nil || deleted { if deleted {
return nil return nil
} }
viewer := widgets.NewMessageViewer(acct, aerc.Config(), store, msg) viewer := widgets.NewMessageViewer(acct, aerc.Config(), store, msg)