summaryrefslogtreecommitdiff
path: root/plugins/Import/src/dbrw
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2021-06-05 17:50:34 +0300
committerGeorge Hazan <ghazan@miranda.im>2021-06-05 17:50:34 +0300
commitd7c9eb34f80f207efd47d2fc65e31aedf166c323 (patch)
tree338b9b905674dc31b1efab739dfcedeed3d8d7b3 /plugins/Import/src/dbrw
parentffc5a3d7550528281976745279e77ac9faba551b (diff)
major code cleaning in regard to db_event_getBlobSize & event memory allocation
Diffstat (limited to 'plugins/Import/src/dbrw')
-rw-r--r--plugins/Import/src/dbrw/dbevents.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/plugins/Import/src/dbrw/dbevents.cpp b/plugins/Import/src/dbrw/dbevents.cpp
index ceb1a9a8f4..4fcfa650fe 100644
--- a/plugins/Import/src/dbrw/dbevents.cpp
+++ b/plugins/Import/src/dbrw/dbevents.cpp
@@ -78,17 +78,23 @@ STDMETHODIMP_(BOOL) CDbxSQLite::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei)
sqlite3_stmt *stmt = evt_stmts_prep[SQL_EVT_STMT_GET];
sqlite3_bind_int(stmt, 1, hDbEvent);
if (sql_step(stmt) == SQLITE_ROW) {
- unsigned copySize;
const void *blob = sqlite3_column_blob(stmt, 4);
- const unsigned size = sqlite3_column_int(stmt, 5);
dbei->timestamp = (DWORD)sqlite3_column_int(stmt, 1);
dbei->flags = (DWORD)sqlite3_column_int(stmt, 2);
dbei->eventType = (WORD)sqlite3_column_int(stmt, 3);
dbei->szModule = mir_strdup((char*)sqlite3_column_text(stmt, 7));
- copySize = size<dbei->cbBlob ? size : dbei->cbBlob;
- memcpy(dbei->pBlob, blob, copySize);
- dbei->cbBlob = copySize;
+
+ DWORD cbBlob = sqlite3_column_int(stmt, 5);
+ size_t bytesToCopy = cbBlob;
+ if (dbei->cbBlob == -1)
+ dbei->pBlob = (PBYTE)mir_calloc(cbBlob + 2);
+ else if (dbei->cbBlob < cbBlob)
+ bytesToCopy = dbei->cbBlob;
+
+ dbei->cbBlob = cbBlob;
+ if (bytesToCopy && dbei->pBlob)
+ memcpy(dbei->pBlob, blob, bytesToCopy);
res = 0;
}
sql_reset(stmt);