[PATCH] Fix crash when no message is selected
Export this patch
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.
---
commands/account/view.go | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/commands/account/view.go b/commands/account/view.go
index b287406..aab9052 100644
--- a/commands/account/view.go
+++ b/commands/account/view.go
@@ -30,8 +30,11 @@ func (ViewMessage) Execute(aerc *widgets.Aerc, args []string) error {
}
store := acct.Messages().Store()
msg := acct.Messages().Selected()
+ if msg == nil {
+ return nil
+ }
_, deleted := store.Deleted[msg.Uid]
- if msg == nil || deleted {
+ if deleted {
return nil
}
viewer := widgets.NewMessageViewer(acct, aerc.Config(), store, msg)
--
2.24.0
Thanks!
To git.sr.ht:~sircmpwn/aerc
31e3e9f..abd9e78 master -> master