Fix null dereference in FeedsModel when a feed isn't found

This is easily reproducible by trying to view the model in GammaRay.
This commit is contained in:
Joshua Goins 2025-01-25 20:04:36 -05:00 committed by Bart De Vries
parent 93308f91e0
commit 981ee01dbd

View File

@ -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();
}