about summary refs log tree commit diff stats
path: root/commands/account
diff options
context:
space:
mode:
authorWiktor Kwapisiewicz <wiktor@metacode.biz>2019-11-28 19:20:45 +0100
committerDrew DeVault <sir@cmpwn.com>2019-12-04 09:45:07 -0500
commitabd9e78f024580d476cb299a575a7aa54c53a4b4 (patch)
tree932b3d04383dcff7764bdcdbc2980abe68d9ab0a /commands/account
parent31e3e9f56e0b8123f0238537112496b407055aef (diff)
downloadaerc-abd9e78f024580d476cb299a575a7aa54c53a4b4.tar.gz
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.
Diffstat (limited to 'commands/account')
-rw-r--r--commands/account/view.go5
1 files changed, 4 insertions, 1 deletions
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)