diff options
author | George Hazan <george.hazan@gmail.com> | 2014-03-02 16:22:08 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-03-02 16:22:08 +0000 |
commit | 79939e2f78e89f4581cfbcc19818c756ece26ad6 (patch) | |
tree | 2f0e05128c67a16b5bdbf792c4b00b4144a44dfc /plugins/Db3x_mmap/src/dbevents.cpp | |
parent | 7561a800c3ddb9f4f2b609b6f28ac39e26e26505 (diff) |
ugh... more solid fix for events convertor
git-svn-id: http://svn.miranda-ng.org/main/trunk@8361 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Db3x_mmap/src/dbevents.cpp')
-rw-r--r-- | plugins/Db3x_mmap/src/dbevents.cpp | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/plugins/Db3x_mmap/src/dbevents.cpp b/plugins/Db3x_mmap/src/dbevents.cpp index 41782ec970..9cf7fd68b6 100644 --- a/plugins/Db3x_mmap/src/dbevents.cpp +++ b/plugins/Db3x_mmap/src/dbevents.cpp @@ -356,42 +356,48 @@ STDMETHODIMP_(HANDLE) CDb3Mmap::FindPrevEvent(HANDLE hDbEvent) void CDb3Mmap::ConvertContactEvents(DBContact *cc)
{
- mir_ptr<BYTE> pBlob((PBYTE)mir_alloc(65536));
+ BYTE *pBlob = (PBYTE)mir_alloc(65536);
DWORD ofsPrev = 0;
- for (DWORD ofsEvent = cc->ofsFirstEvent; ofsEvent != 0;) {
- DBEvent_094 pOld = *(DBEvent_094*)DBRead(ofsEvent, sizeof(DBEvent_094), NULL);
- if (pOld.signature != DBEVENT_SIGNATURE)
- break;
+ __try {
+ for (DWORD ofsEvent = cc->ofsFirstEvent; ofsEvent != 0;) {
+ DBEvent_094 pOld = *(DBEvent_094*)DBRead(ofsEvent, sizeof(DBEvent_094), NULL);
+ if (pOld.signature != DBEVENT_SIGNATURE)
+ break;
- if (pOld.cbBlob >= 65536) {
- ofsEvent = pOld.ofsNext;
- continue;
- }
- memcpy(pBlob, m_pDbCache + ofsEvent + offsetof(DBEvent_094, blob), pOld.cbBlob);
+ if (pOld.cbBlob >= 65536) {
+ ofsEvent = pOld.ofsNext;
+ continue;
+ }
+ memcpy(pBlob, m_pDbCache + ofsEvent + offsetof(DBEvent_094, blob), pOld.cbBlob);
+
+ DWORD ofsNew = ReallocSpace(ofsEvent, offsetof(DBEvent_094, blob) + pOld.cbBlob, offsetof(DBEvent, blob) + pOld.cbBlob);
+ DBEvent *pNew = (DBEvent*)&m_pDbCache[ofsNew];
+ pNew->signature = pOld.signature;
+ pNew->contactID = cc->dwContactID;
+ memcpy(&pNew->ofsPrev, &pOld.ofsPrev, offsetof(DBEvent_094, blob) - sizeof(DWORD));
+ memcpy(&pNew->blob, pBlob, pNew->cbBlob);
+
+ if (ofsPrev == 0) // first event
+ cc->ofsFirstEvent = ofsNew, pNew->ofsPrev = 0;
+ else {
+ DBEvent *pPrev = (DBEvent*)&m_pDbCache[ofsPrev];
+ pPrev->ofsNext = ofsNew, pNew->ofsPrev = ofsPrev;
+ }
- DWORD ofsNew = ReallocSpace(ofsEvent, offsetof(DBEvent_094, blob) + pOld.cbBlob, offsetof(DBEvent, blob) + pOld.cbBlob);
- DBEvent *pNew = (DBEvent*)&m_pDbCache[ofsNew];
- pNew->signature = pOld.signature;
- pNew->contactID = cc->dwContactID;
- memcpy(&pNew->ofsPrev, &pOld.ofsPrev, offsetof(DBEvent_094, blob) - sizeof(DWORD));
- memcpy(&pNew->blob, pBlob, pNew->cbBlob);
+ if (cc->ofsFirstUnread == ofsEvent)
+ cc->ofsFirstUnread = ofsNew;
+ if (cc->ofsLastEvent == ofsEvent)
+ cc->ofsLastEvent = ofsNew;
- if (ofsPrev == 0) // first event
- cc->ofsFirstEvent = ofsNew, pNew->ofsPrev = 0;
- else {
- DBEvent *pPrev = (DBEvent*)&m_pDbCache[ofsPrev];
- pPrev->ofsNext = ofsNew, pNew->ofsPrev = ofsPrev;
+ ofsPrev = ofsNew;
+ ofsEvent = pNew->ofsNext;
}
-
- if (cc->ofsFirstUnread == ofsEvent)
- cc->ofsFirstUnread = ofsNew;
- if (cc->ofsLastEvent == ofsEvent)
- cc->ofsLastEvent = ofsNew;
-
- ofsPrev = ofsNew;
- ofsEvent = pNew->ofsNext;
}
+ __except (EXCEPTION_EXECUTE_HANDLER)
+ {}
+
+ mir_free(pBlob);
}
void CDb3Mmap::ConvertEvents()
|