From b9f735d6457050e326b1b50323dfc0d3b4e03114 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Wed, 10 Sep 2014 21:30:23 +0000 Subject: Tox: fixed crash on contact adding/removing git-svn-id: http://svn.miranda-ng.org/main/trunk@10425 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_contacts.cpp | 10 +++++----- protocols/Tox/src/tox_proto.cpp | 12 +++++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'protocols') diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp index 26159350ae..e148a6ef9a 100644 --- a/protocols/Tox/src/tox_contacts.cpp +++ b/protocols/Tox/src/tox_contacts.cpp @@ -97,7 +97,7 @@ MCONTACT CToxProto::AddContact(const std::vector &id, bool isTemporary) hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); CallService(MS_PROTO_ADDTOCONTACT, hContact, (LPARAM)m_szModuleName); - db_set_blob(hContact, m_szModuleName, TOX_SETTINGS_ID, (uint8_t*)id.data(), TOX_CLIENT_ID_SIZE); + db_set_blob(hContact, m_szModuleName, TOX_SETTINGS_ID, (uint8_t*)id.data(), id.size()); setByte(hContact, "Auth", 1); DBVARIANT dbv; @@ -154,10 +154,10 @@ void CToxProto::LoadFriendList() int CToxProto::OnContactDeleted(MCONTACT hContact, LPARAM lParam) { - if (hContact) + if (hContact && IsOnline()) { DBVARIANT dbv; - std::vector id; + std::vector id(TOX_CLIENT_ID_SIZE); if (!db_get(hContact, m_szModuleName, TOX_SETTINGS_ID, &dbv)) { if (dbv.type != DBVT_BLOB) @@ -186,10 +186,10 @@ void CToxProto::OnFriendRequest(Tox *tox, const uint8_t *address, const uint8_t CToxProto *proto = (CToxProto*)arg; // trim tox address to tox id - std::vector clientId(address, address + TOX_CLIENT_ID_SIZE); + std::vector clientId(address, address + TOX_FRIEND_ADDRESS_SIZE); std::string id = proto->DataToHexString(clientId); - MCONTACT hContact = proto->AddContact(clientId, true); + MCONTACT hContact = proto->AddContact(clientId); PROTORECVEVENT pre = { 0 }; pre.flags = PREF_UTF; diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp index 4bd9ca4efc..33f05487ed 100644 --- a/protocols/Tox/src/tox_proto.cpp +++ b/protocols/Tox/src/tox_proto.cpp @@ -83,7 +83,10 @@ MCONTACT __cdecl CToxProto::AddToList(int flags, PROTOSEARCHRESULT* psr) return AddContact(id, flags & PALF_TEMPORARY); } -MCONTACT __cdecl CToxProto::AddToListByEvent(int flags, int iContact, HANDLE hDbEvent) { return 0; } +MCONTACT __cdecl CToxProto::AddToListByEvent(int flags, int iContact, HANDLE hDbEvent) +{ + return 0; +} int __cdecl CToxProto::Authorize(HANDLE hDbEvent) { @@ -96,10 +99,13 @@ int __cdecl CToxProto::Authorize(HANDLE hDbEvent) } DBVARIANT dbv; - if (!db_get(NULL, m_szModuleName, TOX_SETTINGS_ID, &dbv)) + if (!db_get(hContact, m_szModuleName, TOX_SETTINGS_ID, &dbv)) { - if (tox_add_friend_norequest(tox, (uint8_t*)dbv.pbVal) != TOX_ERROR) + std::vector id(TOX_CLIENT_ID_SIZE); + memcpy(&id[0], dbv.pbVal, TOX_CLIENT_ID_SIZE); + if (tox_add_friend_norequest(tox, id.data()) != TOX_ERROR) { + db_unset(hContact, m_szModuleName, "Auth"); SaveToxData(); db_free(&dbv); return 0; -- cgit v1.2.3