about summary refs log tree commit diff stats
path: root/commands/account/view.go
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/view.go
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/view.go')
-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)
8' href='#n178'>178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307