diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index e87f976e3..df9c75bde 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -420,9 +420,13 @@ namespace App { data->access = UserNoAccess; status = &emptyStatus; } else { + // apply first_name and last_name from minimal user only if we don't have + // local values for first name and last name already, otherwise skip + bool noLocalName = data->firstName.isEmpty() && data->lastName.isEmpty(); + QString fname = (!minimal || noLocalName) ? (d.has_first_name() ? textOneLine(qs(d.vfirst_name)) : QString()) : data->firstName; + QString lname = (!minimal || noLocalName) ? (d.has_last_name() ? textOneLine(qs(d.vlast_name)) : QString()) : data->lastName; + QString phone = minimal ? data->phone : (d.has_phone() ? qs(d.vphone) : QString()); - QString fname = d.has_first_name() ? textOneLine(qs(d.vfirst_name)) : QString(); - QString lname = d.has_last_name() ? textOneLine(qs(d.vlast_name)) : QString(); QString uname = minimal ? data->username : (d.has_username() ? textOneLine(qs(d.vusername)) : QString()); bool phoneChanged = (data->phone != phone); diff --git a/Telegram/SourceFiles/application.cpp b/Telegram/SourceFiles/application.cpp index e3a454a11..28530ed5f 100644 --- a/Telegram/SourceFiles/application.cpp +++ b/Telegram/SourceFiles/application.cpp @@ -1004,7 +1004,7 @@ void AppClass::uploadProfilePhoto(const QImage &tosend, const PeerId &peerId) { QBuffer jpegBuffer(&jpeg); full.save(&jpegBuffer, "JPG", 87); - PhotoId id = MTP::nonce(); + PhotoId id = rand_value(); MTPPhoto photo(MTP_photo(MTP_long(id), MTP_long(0), MTP_int(unixtime()), MTP_vector(photoSizes))); diff --git a/Telegram/SourceFiles/autoupdater.cpp b/Telegram/SourceFiles/autoupdater.cpp index e008a39d5..0734becdf 100644 --- a/Telegram/SourceFiles/autoupdater.cpp +++ b/Telegram/SourceFiles/autoupdater.cpp @@ -58,7 +58,7 @@ void UpdateChecker::initOutput() { fileName = m.captured(1).replace(QRegularExpression(qsl("[^a-zA-Z0-9_\\-]")), QString()); } if (fileName.isEmpty()) { - fileName = qsl("tupdate-%1").arg(MTP::nonce() % 1000000); + fileName = qsl("tupdate-%1").arg(rand_value() % 1000000); } QString dirStr = cWorkingDir() + qsl("tupdates/"); fileName = dirStr + fileName; diff --git a/Telegram/SourceFiles/boxes/addcontactbox.cpp b/Telegram/SourceFiles/boxes/addcontactbox.cpp index 0d4178a5d..5f3457ca7 100644 --- a/Telegram/SourceFiles/boxes/addcontactbox.cpp +++ b/Telegram/SourceFiles/boxes/addcontactbox.cpp @@ -188,11 +188,11 @@ void AddContactBox::onSave() { } _sentName = firstName; if (_user) { - _contactId = MTP::nonce(); + _contactId = rand_value(); QVector v(1, MTP_inputPhoneContact(MTP_long(_contactId), MTP_string(_user->phone), MTP_string(firstName), MTP_string(lastName))); _addRequest = MTP::send(MTPcontacts_ImportContacts(MTP_vector(v), MTP_bool(false)), rpcDone(&AddContactBox::onSaveUserDone), rpcFail(&AddContactBox::onSaveUserFail)); } else { - _contactId = MTP::nonce(); + _contactId = rand_value(); QVector v(1, MTP_inputPhoneContact(MTP_long(_contactId), MTP_string(phone), MTP_string(firstName), MTP_string(lastName))); _addRequest = MTP::send(MTPcontacts_ImportContacts(MTP_vector(v), MTP_bool(false)), rpcDone(&AddContactBox::onImportDone)); } diff --git a/Telegram/SourceFiles/boxes/contactsbox.cpp b/Telegram/SourceFiles/boxes/contactsbox.cpp index 72d9397c2..803cd32e0 100644 --- a/Telegram/SourceFiles/boxes/contactsbox.cpp +++ b/Telegram/SourceFiles/boxes/contactsbox.cpp @@ -224,7 +224,7 @@ void ContactsInner::onPeerNameChanged(PeerData *peer, const PeerData::Names &old void ContactsInner::onAddBot() { if (_bot->botInfo && !_bot->botInfo->startGroupToken.isEmpty()) { - MTP::send(MTPmessages_StartBot(_bot->inputUser, _addToPeer->input, MTP_long(MTP::nonce()), MTP_string(_bot->botInfo->startGroupToken)), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::addParticipantFail, _bot)); + MTP::send(MTPmessages_StartBot(_bot->inputUser, _addToPeer->input, MTP_long(rand_value()), MTP_string(_bot->botInfo->startGroupToken)), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::addParticipantFail, _bot)); } else { App::main()->addParticipants(_addToPeer, QVector(1, _bot)); } diff --git a/Telegram/SourceFiles/gui/animation.cpp b/Telegram/SourceFiles/gui/animation.cpp index 1e9af9fe2..6628f6ef2 100644 --- a/Telegram/SourceFiles/gui/animation.cpp +++ b/Telegram/SourceFiles/gui/animation.cpp @@ -245,7 +245,7 @@ ClipReader::ClipReader(const FileLocation &location, const QByteArray &data, Cal _clipManagers.push_back(new ClipReadManager(_clipThreads.back())); _clipThreads.back()->start(); } else { - _threadIndex = int32(MTP::nonce() % _clipThreads.size()); + _threadIndex = int32(rand_value() % _clipThreads.size()); int32 loadLevel = 0x7FFFFFFF; for (int32 i = 0, l = _clipThreads.size(); i < l; ++i) { int32 level = _clipManagers.at(i)->loadLevel(); diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 8476a665c..174b2506d 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -4836,7 +4836,7 @@ void HistoryWidget::onBotStart() { if (token.isEmpty()) { sendBotCommand(qsl("/start"), 0); } else { - uint64 randomId = MTP::nonce(); + uint64 randomId = rand_value(); MTP::send(MTPmessages_StartBot(_peer->asUser()->inputUser, MTP_inputPeerEmpty(), MTP_long(randomId), MTP_string(token)), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::addParticipantFail, _peer->asUser())); _peer->asUser()->botInfo->startToken = QString(); @@ -4897,7 +4897,7 @@ void HistoryWidget::onShareContact(const PeerId &peer, UserData *contact) { void HistoryWidget::shareContact(const PeerId &peer, const QString &phone, const QString &fname, const QString &lname, MsgId replyTo, int32 userId) { History *h = App::history(peer); - uint64 randomId = MTP::nonce(); + uint64 randomId = rand_value(); FullMsgId newId(peerToChannel(peer), clientMsgId()); App::main()->readServerHistory(h, false); @@ -5993,7 +5993,7 @@ void HistoryWidget::onPhotoUploaded(const FullMsgId &newId, bool silent, const M if (!MTP::authedId()) return; HistoryItem *item = App::histItemById(newId); if (item) { - uint64 randomId = MTP::nonce(); + uint64 randomId = rand_value(); App::historyRegRandom(randomId, newId); History *hist = item->history(); MsgId replyTo = item->toHistoryReply() ? item->toHistoryReply()->replyToId() : 0; @@ -6045,7 +6045,7 @@ void HistoryWidget::onDocumentUploaded(const FullMsgId &newId, bool silent, cons if (item) { DocumentData *document = item->getMedia() ? item->getMedia()->getDocument() : 0; if (document) { - uint64 randomId = MTP::nonce(); + uint64 randomId = rand_value(); App::historyRegRandom(randomId, newId); History *hist = item->history(); MsgId replyTo = item->toHistoryReply() ? item->toHistoryReply()->replyToId() : 0; @@ -6074,7 +6074,7 @@ void HistoryWidget::onThumbDocumentUploaded(const FullMsgId &newId, bool silent, if (item) { DocumentData *document = item->getMedia() ? item->getMedia()->getDocument() : 0; if (document) { - uint64 randomId = MTP::nonce(); + uint64 randomId = rand_value(); App::historyRegRandom(randomId, newId); History *hist = item->history(); MsgId replyTo = item->toHistoryReply() ? item->toHistoryReply()->replyToId() : 0; @@ -6799,7 +6799,7 @@ void HistoryWidget::onInlineResultSend(InlineResult *result, UserData *bot) { App::main()->readServerHistory(_history, false); fastShowAtEnd(_history); - uint64 randomId = MTP::nonce(); + uint64 randomId = rand_value(); FullMsgId newId(_channel, clientMsgId()); bool lastKeyboardUsed = lastForceReplyReplied(); @@ -6854,7 +6854,7 @@ void HistoryWidget::onInlineResultSend(InlineResult *result, UserData *bot) { tw = th = 0; thumbSize = MTP_photoSizeEmpty(MTP_string("")); } - uint64 docId = MTP::nonce(); + uint64 docId = rand_value(); QVector attributes(1, MTP_documentAttributeFilename(MTP_string((result->content_type == qstr("video/mp4") ? "animation.gif.mp4" : "animation.gif")))); attributes.push_back(MTP_documentAttributeAnimated()); attributes.push_back(MTP_documentAttributeVideo(MTP_int(result->duration), MTP_int(result->width), MTP_int(result->height))); @@ -6878,7 +6878,7 @@ void HistoryWidget::onInlineResultSend(InlineResult *result, UserData *bot) { photoSizes.push_back(MTP_photoSize(MTP_string("x"), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(result->width), MTP_int(result->height), MTP_int(0))); - uint64 photoId = MTP::nonce(); + uint64 photoId = rand_value(); PhotoData *ph = App::photoSet(photoId, 0, 0, unixtime(), thumbPtr, ImagePtr(medium.width(), medium.height()), ImagePtr(result->width, result->height)); MTPPhoto photo = MTP_photo(MTP_long(photoId), MTP_long(0), MTP_int(ph->date), MTP_vector(photoSizes)); @@ -7020,7 +7020,7 @@ void HistoryWidget::sendExistingDocument(DocumentData *doc, const QString &capti App::main()->readServerHistory(_history, false); fastShowAtEnd(_history); - uint64 randomId = MTP::nonce(); + uint64 randomId = rand_value(); FullMsgId newId(_channel, clientMsgId()); bool lastKeyboardUsed = lastForceReplyReplied(); @@ -7076,7 +7076,7 @@ void HistoryWidget::sendExistingPhoto(PhotoData *photo, const QString &caption) App::main()->readServerHistory(_history, false); fastShowAtEnd(_history); - uint64 randomId = MTP::nonce(); + uint64 randomId = rand_value(); FullMsgId newId(_channel, clientMsgId()); bool lastKeyboardUsed = lastForceReplyReplied(); diff --git a/Telegram/SourceFiles/localimageloader.cpp b/Telegram/SourceFiles/localimageloader.cpp index 498d43831..7ae676ce2 100644 --- a/Telegram/SourceFiles/localimageloader.cpp +++ b/Telegram/SourceFiles/localimageloader.cpp @@ -171,7 +171,7 @@ void TaskQueueWorker::onTaskAdded() { _inTaskAdded = false; } -FileLoadTask::FileLoadTask(const QString &filepath, PrepareMediaType type, const FileLoadTo &to, FileLoadForceConfirmType confirm) : _id(MTP::nonce()) +FileLoadTask::FileLoadTask(const QString &filepath, PrepareMediaType type, const FileLoadTo &to, FileLoadForceConfirmType confirm) : _id(rand_value()) , _to(to) , _filepath(filepath) , _duration(0) @@ -180,7 +180,7 @@ FileLoadTask::FileLoadTask(const QString &filepath, PrepareMediaType type, const , _result(0) { } -FileLoadTask::FileLoadTask(const QByteArray &content, PrepareMediaType type, const FileLoadTo &to) : _id(MTP::nonce()) +FileLoadTask::FileLoadTask(const QByteArray &content, PrepareMediaType type, const FileLoadTo &to) : _id(rand_value()) , _to(to) , _content(content) , _duration(0) @@ -189,7 +189,7 @@ FileLoadTask::FileLoadTask(const QByteArray &content, PrepareMediaType type, con , _result(0) { } -FileLoadTask::FileLoadTask(const QImage &image, PrepareMediaType type, const FileLoadTo &to, FileLoadForceConfirmType confirm, const QString &originalText) : _id(MTP::nonce()) +FileLoadTask::FileLoadTask(const QImage &image, PrepareMediaType type, const FileLoadTo &to, FileLoadForceConfirmType confirm, const QString &originalText) : _id(rand_value()) , _to(to) , _image(image) , _duration(0) @@ -199,7 +199,7 @@ FileLoadTask::FileLoadTask(const QImage &image, PrepareMediaType type, const Fil , _result(0) { } -FileLoadTask::FileLoadTask(const QByteArray &voice, int32 duration, const VoiceWaveform &waveform, const FileLoadTo &to) : _id(MTP::nonce()) +FileLoadTask::FileLoadTask(const QByteArray &voice, int32 duration, const VoiceWaveform &waveform, const FileLoadTo &to) : _id(rand_value()) , _to(to) , _content(voice) , _duration(duration) @@ -323,7 +323,7 @@ void FileLoadTask::process() { thumb = full; thumbSize = MTP_photoSize(MTP_string(""), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(full.width()), MTP_int(full.height()), MTP_int(0)); - thumbId = MTP::nonce(); + thumbId = rand_value(); } } } @@ -350,7 +350,7 @@ void FileLoadTask::process() { thumb = full; thumbSize = MTP_photoSize(MTP_string(""), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(full.width()), MTP_int(full.height()), MTP_int(0)); - thumbId = MTP::nonce(); + thumbId = rand_value(); if (filename.endsWith(qstr(".mp4"), Qt::CaseInsensitive)) { filemime = qstr("video/mp4"); @@ -406,7 +406,7 @@ void FileLoadTask::process() { thumb = full; thumbSize = MTP_photoSize(MTP_string(""), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(full.width()), MTP_int(full.height()), MTP_int(0)); - thumbId = MTP::nonce(); + thumbId = rand_value(); } } diff --git a/Telegram/SourceFiles/localimageloader.h b/Telegram/SourceFiles/localimageloader.h index 6e6b5a0ee..49266a7a8 100644 --- a/Telegram/SourceFiles/localimageloader.h +++ b/Telegram/SourceFiles/localimageloader.h @@ -29,13 +29,13 @@ enum PrepareMediaType { }; struct ToPrepareMedia { - ToPrepareMedia(const QString &file, const PeerId &peer, PrepareMediaType t, bool broadcast, bool ctrlShiftEnter, MsgId replyTo) : id(MTP::nonce()), file(file), peer(peer), type(t), duration(0), ctrlShiftEnter(ctrlShiftEnter), replyTo(replyTo) { + ToPrepareMedia(const QString &file, const PeerId &peer, PrepareMediaType t, bool broadcast, bool ctrlShiftEnter, MsgId replyTo) : id(rand_value()), file(file), peer(peer), type(t), duration(0), ctrlShiftEnter(ctrlShiftEnter), replyTo(replyTo) { } - ToPrepareMedia(const QImage &img, const PeerId &peer, PrepareMediaType t, bool broadcast, bool ctrlShiftEnter, MsgId replyTo) : id(MTP::nonce()), img(img), peer(peer), type(t), duration(0), ctrlShiftEnter(ctrlShiftEnter), replyTo(replyTo) { + ToPrepareMedia(const QImage &img, const PeerId &peer, PrepareMediaType t, bool broadcast, bool ctrlShiftEnter, MsgId replyTo) : id(rand_value()), img(img), peer(peer), type(t), duration(0), ctrlShiftEnter(ctrlShiftEnter), replyTo(replyTo) { } - ToPrepareMedia(const QByteArray &data, const PeerId &peer, PrepareMediaType t, bool broadcast, bool ctrlShiftEnter, MsgId replyTo) : id(MTP::nonce()), data(data), peer(peer), type(t), duration(0), ctrlShiftEnter(ctrlShiftEnter), replyTo(replyTo) { + ToPrepareMedia(const QByteArray &data, const PeerId &peer, PrepareMediaType t, bool broadcast, bool ctrlShiftEnter, MsgId replyTo) : id(rand_value()), data(data), peer(peer), type(t), duration(0), ctrlShiftEnter(ctrlShiftEnter), replyTo(replyTo) { } - ToPrepareMedia(const QByteArray &data, int32 duration, const PeerId &peer, PrepareMediaType t, bool broadcast, bool ctrlShiftEnter, MsgId replyTo) : id(MTP::nonce()), data(data), peer(peer), type(t), duration(duration), ctrlShiftEnter(ctrlShiftEnter), replyTo(replyTo) { + ToPrepareMedia(const QByteArray &data, int32 duration, const PeerId &peer, PrepareMediaType t, bool broadcast, bool ctrlShiftEnter, MsgId replyTo) : id(rand_value()), data(data), peer(peer), type(t), duration(duration), ctrlShiftEnter(ctrlShiftEnter), replyTo(replyTo) { } PhotoId id; QString file; diff --git a/Telegram/SourceFiles/localstorage.cpp b/Telegram/SourceFiles/localstorage.cpp index 102e5a9c0..b75e86761 100644 --- a/Telegram/SourceFiles/localstorage.cpp +++ b/Telegram/SourceFiles/localstorage.cpp @@ -113,7 +113,7 @@ namespace { path.reserve(base.size() + 0x11); path += base; do { - result = MTP::nonce(); + result = rand_value(); path.resize(base.size()); path += toFilePart(result); } while (!result || keyAlreadyUsed(path, options)); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index a4a98df02..1833b4296 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -637,7 +637,7 @@ void MainWidget::finishForwarding(History *hist, bool broadcast, bool silent) { ids.reserve(_toForward.size()); randomIds.reserve(_toForward.size()); for (SelectedItemSet::const_iterator i = _toForward.cbegin(), e = _toForward.cend(); i != e; ++i) { - uint64 randomId = MTP::nonce(); + uint64 randomId = rand_value(); if (genClientSideMessage) { FullMsgId newId(peerToChannel(hist->peer->id), clientMsgId()); HistoryMessage *msg = static_cast(_toForward.cbegin().value()); @@ -1366,7 +1366,7 @@ void MainWidget::sendMessage(History *hist, const QString &text, MsgId replyTo, if (replyTo < 0) replyTo = history.replyToId(); while (textSplit(sendingText, sendingEntities, leftText, leftEntities, MaxMessageSize)) { FullMsgId newId(peerToChannel(hist->peer->id), clientMsgId()); - uint64 randomId = MTP::nonce(); + uint64 randomId = rand_value(); trimTextWithEntities(sendingText, sendingEntities); diff --git a/Telegram/SourceFiles/mtproto/connection.cpp b/Telegram/SourceFiles/mtproto/connection.cpp index a5cb1d6bf..c999179bb 100644 --- a/Telegram/SourceFiles/mtproto/connection.cpp +++ b/Telegram/SourceFiles/mtproto/connection.cpp @@ -648,8 +648,8 @@ void AbstractTcpConnection::socketRead() { AutoConnection::AutoConnection(QThread *thread) : AbstractTcpConnection() , status(WaitingBoth) -, tcpNonce(MTP::nonce()) -, httpNonce(MTP::nonce()) +, tcpNonce(rand_value()) +, httpNonce(rand_value()) , _flagsTcp(0) , _flagsHttp(0) , _tcpTimeout(MTPMinReceiveDelay) { @@ -1000,7 +1000,7 @@ void AutoConnection::socketError(QAbstractSocket::SocketError e) { TCPConnection::TCPConnection(QThread *thread) : status(WaitingTcp) - , tcpNonce(MTP::nonce()) + , tcpNonce(rand_value()) , _tcpTimeout(MTPMinReceiveDelay) , _flags(0) { moveToThread(thread); @@ -1162,7 +1162,7 @@ void TCPConnection::socketError(QAbstractSocket::SocketError e) { HTTPConnection::HTTPConnection(QThread *thread) : status(WaitingHttp) - , httpNonce(MTP::nonce()) + , httpNonce(rand_value()) , _flags(0) { moveToThread(thread); manager.moveToThread(thread); @@ -1541,7 +1541,7 @@ void ConnectionPrivate::resetSession() { // recreate all msg_id and msg_seqno } } - uint64 session = MTP::nonce(); + uint64 session = rand_value(); DEBUG_LOG(("MTP Info: creating new session after bad_msg_notification, setting random server_session %1").arg(session)); sessionData->setSession(session); @@ -1698,7 +1698,7 @@ void ConnectionPrivate::tryToSend() { mtpRequest pingRequest; if (dc == bareDcId(dc)) { // main session if (!prependOnly && !_pingIdToSend && !_pingId && _pingSendAt <= getms(true)) { - _pingIdToSend = MTP::nonce(); + _pingIdToSend = rand_value(); } } if (_pingIdToSend) { @@ -3317,7 +3317,7 @@ void ConnectionPrivate::updateAuthKey() { authKeyData = new ConnectionPrivate::AuthKeyCreateData(); authKeyStrings = new ConnectionPrivate::AuthKeyCreateStrings(); authKeyData->req_num = 0; - authKeyData->nonce = MTP::nonce(); + authKeyData->nonce = rand_value(); MTPReq_pq req_pq; req_pq.vnonce = authKeyData->nonce; @@ -3390,7 +3390,7 @@ void ConnectionPrivate::pqAnswered() { return restart(); } - authKeyData->new_nonce = MTP::nonce(); + authKeyData->new_nonce = rand_value(); p_q_inner_data.vnew_nonce = authKeyData->new_nonce; MTPReq_DH_params req_DH_params; @@ -3748,7 +3748,7 @@ void ConnectionPrivate::authKeyCreated() { } } - _pingIdToSend = MTP::nonce(); // get server_salt + _pingIdToSend = rand_value(); // get server_salt emit needToSendAsync(); } diff --git a/Telegram/SourceFiles/mtproto/facade.h b/Telegram/SourceFiles/mtproto/facade.h index 912fee118..05990fde2 100644 --- a/Telegram/SourceFiles/mtproto/facade.h +++ b/Telegram/SourceFiles/mtproto/facade.h @@ -192,13 +192,6 @@ void clearGlobalHandlers(); void updateDcOptions(const QVector &options); -template -T nonce() { - T result; - memset_rand(&result, sizeof(T)); - return result; -} - mtpKeysMap getKeys(); void setKey(int32 dc, mtpAuthKeyPtr key); diff --git a/Telegram/SourceFiles/mtproto/session.h b/Telegram/SourceFiles/mtproto/session.h index 49285f606..39a15acc5 100644 --- a/Telegram/SourceFiles/mtproto/session.h +++ b/Telegram/SourceFiles/mtproto/session.h @@ -78,8 +78,7 @@ public: } void setKey(const mtpAuthKeyPtr &key) { if (_authKey != key) { - uint64 session; - memsetrnd(session); + uint64 session = rand_value(); _authKey = key; DEBUG_LOG(("MTP Info: new auth key set in SessionData, id %1, setting random server_session %2").arg(key ? key->keyId() : 0).arg(session)); diff --git a/Telegram/SourceFiles/pspecific_win.cpp b/Telegram/SourceFiles/pspecific_win.cpp index 4a2aa5a69..4153318b7 100644 --- a/Telegram/SourceFiles/pspecific_win.cpp +++ b/Telegram/SourceFiles/pspecific_win.cpp @@ -3241,7 +3241,7 @@ QString toastImage(const StorageKey &key, PeerData *peer) { } else { v.until = 0; } - v.path = cWorkingDir() + qsl("tdata/temp/") + QString::number(MTP::nonce(), 16) + qsl(".png"); + v.path = cWorkingDir() + qsl("tdata/temp/") + QString::number(rand_value(), 16) + qsl(".png"); if (key.first || key.second) { peer->saveUserpic(v.path); } else { diff --git a/Telegram/SourceFiles/pspecific_winrt.cpp b/Telegram/SourceFiles/pspecific_winrt.cpp index ae9f029a4..49d8ef081 100644 --- a/Telegram/SourceFiles/pspecific_winrt.cpp +++ b/Telegram/SourceFiles/pspecific_winrt.cpp @@ -2655,7 +2655,7 @@ void psWriteDump() { // } else { // v.until = 0; // } -// v.path = cWorkingDir() + qsl("tdata/temp/") + QString::number(MTP::nonce(), 16) + qsl(".png"); +// v.path = cWorkingDir() + qsl("tdata/temp/") + QString::number(rand_value(), 16) + qsl(".png"); // if (key.first || key.second) { // peer->saveUserpic(v.path); // } else { diff --git a/Telegram/SourceFiles/types.h b/Telegram/SourceFiles/types.h index 6f9a05585..fd6ea2438 100644 --- a/Telegram/SourceFiles/types.h +++ b/Telegram/SourceFiles/types.h @@ -239,11 +239,13 @@ inline char *hashMd5Hex(const void *data, uint32 len, void *dest) { // dest = pt return hashMd5Hex(HashMd5(data, len).result(), dest); } +// good random (using openssl implementation) void memset_rand(void *data, uint32 len); - template -inline void memsetrnd(T &value) { - memset_rand(&value, sizeof(value)); +T rand_value() { + T result; + memset_rand(&result, sizeof(result)); + return result; } inline void memset_rand_bad(void *data, uint32 len) {