Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(core, widget): Added checks
Browse files Browse the repository at this point in the history
Fix #3133.
* Added check, that core and coreAv exist, before use them
* Added check, that tox exit, before use them
  • Loading branch information
Diadlo committed Apr 14, 2016
1 parent 0a2f541 commit f28c3a1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,12 @@ ToxId Core::getGroupPeerToxId(int groupId, int peerId) const
QList<QString> Core::getGroupPeerNames(int groupId) const
{
QList<QString> names;
if (!tox)
{
qWarning() << "Can't get group peer names, tox is null";
return names;
}

int result = getGroupNumberPeers(groupId);
if (result < 0)
{
Expand Down
24 changes: 22 additions & 2 deletions src/widget/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1502,8 +1502,11 @@ void Widget::onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t Cha
{
qDebug() << "onGroupNamelistChanged: Group "<<groupnumber<<" not found, creating it";
g = createGroup(groupnumber);
if (!g)
return;
}


TOX_CHAT_CHANGE change = static_cast<TOX_CHAT_CHANGE>(Change);
if (change == TOX_CHAT_CHANGE_PEER_ADD)
{
Expand Down Expand Up @@ -1586,14 +1589,29 @@ Group *Widget::createGroup(int groupId)
Group* g = GroupList::findGroup(groupId);
if (g)
{
qWarning() << "createGroup: Group already exists";
qWarning() << "Group already exists";
return g;
}

Core* core = Nexus::getCore();

if (!core)
{
qWarning() << "Can't create group. Core does not exist";
return nullptr;
}

QString groupName = QString("Groupchat #%1").arg(groupId);
Group* newgroup = GroupList::addGroup(groupId, groupName, core->getAv()->isGroupAvEnabled(groupId));
CoreAV* coreAv = core->getAv();

if (!coreAv)
{
qWarning() << "Can't create group. CoreAv does not exist";
return nullptr;
}

bool enabled = coreAv->isGroupAvEnabled(groupId);
Group* newgroup = GroupList::addGroup(groupId, groupName, enabled);

contactListWidget->addGroupWidget(newgroup->getGroupWidget());
newgroup->getGroupWidget()->updateStatusLight();
Expand All @@ -1615,6 +1633,8 @@ Group *Widget::createGroup(int groupId)
void Widget::onEmptyGroupCreated(int groupId)
{
Group* group = createGroup(groupId);
if (!group)
return;

// Only rename group if groups are visible.
if (Widget::getInstance()->groupsVisible())
Expand Down

0 comments on commit f28c3a1

Please sign in to comment.