mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix: Fix warning about stack protection
Replace local array on stack with dynamic size on QByteArray with dynamic size
This commit is contained in:
parent
8e93af7fca
commit
efcad35fd5
|
@ -1077,20 +1077,21 @@ uint32_t Core::getGroupNumberPeers(int groupId) const
|
||||||
*/
|
*/
|
||||||
QString Core::getGroupPeerName(int groupId, int peerId) const
|
QString Core::getGroupPeerName(int groupId, int peerId) const
|
||||||
{
|
{
|
||||||
uint8_t nameArray[tox_max_name_length()];
|
|
||||||
TOX_ERR_CONFERENCE_PEER_QUERY error;
|
TOX_ERR_CONFERENCE_PEER_QUERY error;
|
||||||
size_t length = tox_conference_peer_get_name_size(tox, groupId, peerId, &error);
|
size_t length = tox_conference_peer_get_name_size(tox, groupId, peerId, &error);
|
||||||
if (!parsePeerQueryError(error)) {
|
if (!parsePeerQueryError(error)) {
|
||||||
return QString{};
|
return QString{};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success = tox_conference_peer_get_name(tox, groupId, peerId, nameArray, &error);
|
QByteArray name(length, Qt::Uninitialized);
|
||||||
|
uint8_t* namePtr = static_cast<uint8_t*>(static_cast<void*>(name.data()));
|
||||||
|
bool success = tox_conference_peer_get_name(tox, groupId, peerId, namePtr, &error);
|
||||||
if (!parsePeerQueryError(error) || !success) {
|
if (!parsePeerQueryError(error) || !success) {
|
||||||
qWarning() << "getGroupPeerName: Unknown error";
|
qWarning() << "getGroupPeerName: Unknown error";
|
||||||
return QString{};
|
return QString{};
|
||||||
}
|
}
|
||||||
|
|
||||||
return ToxString(nameArray, length).getQString();
|
return ToxString(name).getQString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1138,12 +1139,12 @@ QStringList Core::getGroupPeerNames(int groupId) const
|
||||||
|
|
||||||
QStringList names;
|
QStringList names;
|
||||||
for (uint32_t i = 0; i < nPeers; ++i) {
|
for (uint32_t i = 0; i < nPeers; ++i) {
|
||||||
uint8_t name[tox_max_name_length()];
|
|
||||||
memset(name, 0, tox_max_name_length());
|
|
||||||
size_t length = tox_conference_peer_get_name_size(tox, groupId, i, &error);
|
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);
|
QByteArray name(length, Qt::Uninitialized);
|
||||||
|
uint8_t* namePtr = static_cast<uint8_t*>(static_cast<void*>(name.data()));
|
||||||
|
bool ok = tox_conference_peer_get_name(tox, groupId, i, namePtr, &error);
|
||||||
if (ok && parsePeerQueryError(error)) {
|
if (ok && parsePeerQueryError(error)) {
|
||||||
names.append(ToxString(name, length).getQString());
|
names.append(ToxString(name).getQString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user