From 3ee78eadd7647748ae220402c01a062d3f56b4ef Mon Sep 17 00:00:00 2001 From: Simon Redman Date: Sun, 6 Mar 2022 22:56:18 +0000 Subject: [PATCH] [SMS App] Prevent crash if a conversation doesn't have any messages ## Summary Fix crash in kdeconnect-sms if a conversation contains a message which has no addresses. I am not sure why this would happen and there's probably something which should be fixed on the Android side to ensure that every message has addresses, but this is an easy fix to prevent user-reported crashes. BUG: 449719 ## Test Plan ### Before: kdeconnect-sms crashes upon selecting a conversation with a message with no addresses ### After: kdeconnect-sms does not crash --- smsapp/conversationmodel.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/smsapp/conversationmodel.cpp b/smsapp/conversationmodel.cpp index 7cd80abc7..559fd56c4 100644 --- a/smsapp/conversationmodel.cpp +++ b/smsapp/conversationmodel.cpp @@ -142,7 +142,15 @@ void ConversationModel::createRowFromMessage(const ConversationMessage& message, return; } - ConversationAddress sender = message.addresses().first(); + ConversationAddress sender; + if (!message.addresses().isEmpty()) { + sender = message.addresses().first(); + } + else { + qCDebug(KDECONNECT_SMS_CONVERSATION_MODEL) + << "Conversation with ID " << message.threadID() << " did not have any addresses"; + } + QString senderName = message.isIncoming() ? SmsHelper::getTitleForAddresses({sender}) : QString(); QString displayBody = message.body();