From 981ee01dbd696e9c715fd50c8475bc3f889a42d2 Mon Sep 17 00:00:00 2001
From: Joshua Goins <josh@redstrate.com>
Date: Sat, 25 Jan 2025 20:04:36 -0500
Subject: [PATCH] Fix null dereference in FeedsModel when a feed isn't found

This is easily reproducible by trying to view the model in GammaRay.
---
 src/models/feedsmodel.cpp | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/models/feedsmodel.cpp b/src/models/feedsmodel.cpp
index 6852e614..d4ae72bf 100644
--- a/src/models/feedsmodel.cpp
+++ b/src/models/feedsmodel.cpp
@@ -54,20 +54,24 @@ int FeedsModel::rowCount(const QModelIndex &parent) const
 
 QVariant FeedsModel::data(const QModelIndex &index, int role) const
 {
+    const auto feed = DataManager::instance().getFeed(index.row());
+    if (!feed) {
+        return {};
+    }
     switch (role) {
     case FeedRole:
-        return QVariant::fromValue(DataManager::instance().getFeed(index.row()));
+        return QVariant::fromValue(feed);
     case Qt::DisplayRole:
     case UrlRole:
-        return QVariant::fromValue(DataManager::instance().getFeed(index.row())->url());
+        return QVariant::fromValue(feed->url());
     case TitleRole:
-        return QVariant::fromValue(DataManager::instance().getFeed(index.row())->name());
+        return QVariant::fromValue(feed->name());
     case UnreadCountRole:
-        return QVariant::fromValue(DataManager::instance().getFeed(index.row())->unreadEntryCount());
+        return QVariant::fromValue(feed->unreadEntryCount());
     case NewCountRole:
-        return QVariant::fromValue(DataManager::instance().getFeed(index.row())->newEntryCount());
+        return QVariant::fromValue(feed->newEntryCount());
     case FavoriteCountRole:
-        return QVariant::fromValue(DataManager::instance().getFeed(index.row())->favoriteEntryCount());
+        return QVariant::fromValue(feed->favoriteEntryCount());
     default:
         return QVariant();
     }