1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix: fixed segfault after accepting group invite

Fix #4327
Description:
  - QString::arg call with mulpiple arguments replaced with chained
    QString::arg calls;
  - dynamic memory allocation for array of names replaced with
    allocation on the stack, unfortunately I do not notice this while
    making Core refactoring.
Also code style is formatted with script
This commit is contained in:
noavarice 2017-04-12 20:38:14 +03:00
parent 6de129fef1
commit 532e05cb0f

View File

@ -535,7 +535,7 @@ void Core::onGroupNamelistChange(Tox*, uint32_t groupId, uint32_t peerId,
CoreAV::invalidateGroupCallPeerSource(groupId, peerId);
}
qDebug() << QString("Group namelist change %1:%2 %3").arg(groupId, peerId, change);
qDebug() << QString("Group namelist change %1:%2 %3").arg(groupId).arg(peerId).arg(change);
emit static_cast<Core*>(core)->groupNamelistChanged(groupId, peerId, change);
}
@ -1020,17 +1020,17 @@ QByteArray Core::getToxSaveData()
}
// Declared to avoid code duplication
#define GET_FRIEND_PROPERTY(property, function, checkSize)\
const size_t property##Size = function##_size(tox, ids[i], nullptr);\
if ((!checkSize || property##Size) && property##Size != SIZE_MAX) {\
uint8_t* prop = new uint8_t[property##Size];\
if (function(tox, ids[i], prop, nullptr)) {\
QString propStr = ToxString(prop, property##Size).getQString();\
emit friend##property##Changed(ids[i], propStr);\
}\
\
delete[] prop;\
}\
#define GET_FRIEND_PROPERTY(property, function, checkSize) \
const size_t property##Size = function##_size(tox, ids[i], nullptr); \
if ((!checkSize || property##Size) && property##Size != SIZE_MAX) { \
uint8_t* prop = new uint8_t[property##Size]; \
if (function(tox, ids[i], prop, nullptr)) { \
QString propStr = ToxString(prop, property##Size).getQString(); \
emit friend##property##Changed(ids[i], propStr); \
} \
\
delete[] prop; \
}
void Core::loadFriends()
{
@ -1171,10 +1171,7 @@ QStringList Core::getGroupPeerNames(int groupId) const
return {};
}
std::vector<uint8_t*> namesArray(nPeers, new uint8_t[TOX_MAX_NAME_LENGTH]);
std::vector<size_t> lengths(nPeers);
TOX_ERR_CONFERENCE_PEER_QUERY error;
uint32_t count = tox_conference_peer_count(tox, groupId, &error);
if (!parsePeerQueryError(error)) {
return {};
@ -1187,17 +1184,14 @@ QStringList Core::getGroupPeerNames(int groupId) const
QStringList names;
for (uint32_t i = 0; i < nPeers; ++i) {
lengths[i] = tox_conference_peer_get_name_size(tox, groupId, i, &error);
bool ok = tox_conference_peer_get_name(tox, groupId, i, namesArray[i], &error);
if (parsePeerQueryError(error) && ok) {
names.append(ToxString(namesArray[i], lengths[i]).getQString());
uint8_t name[TOX_MAX_NAME_LENGTH] = {0};
size_t length = tox_conference_peer_get_name_size(tox, groupId, i, &error);
bool ok = tox_conference_peer_get_name(tox, groupId, i, name, &error);
if (ok && parsePeerQueryError(error)) {
names.append(ToxString(name, length).getQString());
}
}
for (uint8_t* name : namesArray) {
delete[] name;
}
return names;
}