From 4c814798c7bc7f6a0f92c21b027b26290622aa2f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 19 Jun 2015 19:35:42 +0000 Subject: SIZEOF replaced with more secure analog - _countof git-svn-id: http://svn.miranda-ng.org/main/trunk@14270 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Spamotron/src/bayes.cpp | 16 ++++++++-------- plugins/Spamotron/src/options.cpp | 10 +++++----- plugins/Spamotron/src/spamotron.cpp | 2 +- plugins/Spamotron/src/utils.cpp | 8 ++++---- 4 files changed, 18 insertions(+), 18 deletions(-) (limited to 'plugins/Spamotron') diff --git a/plugins/Spamotron/src/bayes.cpp b/plugins/Spamotron/src/bayes.cpp index 89de53ef23..5fde61bc34 100644 --- a/plugins/Spamotron/src/bayes.cpp +++ b/plugins/Spamotron/src/bayes.cpp @@ -18,7 +18,7 @@ int CheckBayes() char* tmp = Utils_ReplaceVars("%miranda_userdata%"); if (tmp[mir_strlen(tmp)-1] == '\\') tmp[mir_strlen(tmp)-1] = 0; - mir_snprintf(bayesdb_tmp, SIZEOF(bayesdb_tmp), "%s\\%s", tmp, BAYESDB_PATH); + mir_snprintf(bayesdb_tmp, _countof(bayesdb_tmp), "%s\\%s", tmp, BAYESDB_PATH); mir_free(tmp); if (ServiceExists(MS_FOLDERS_REGISTER_PATH)) { @@ -83,7 +83,7 @@ int OpenBayes() tmp = Utils_ReplaceVars("%miranda_userdata%"); if (tmp[mir_strlen(tmp)-1] == '\\') tmp[mir_strlen(tmp)-1] = 0; - mir_snprintf(bayesdb_fullpath, SIZEOF(bayesdb_fullpath), "%s\\%s\\%s", tmp, BAYESDB_PATH, BAYESDBG_FILENAME); + mir_snprintf(bayesdb_fullpath, _countof(bayesdb_fullpath), "%s\\%s\\%s", tmp, BAYESDB_PATH, BAYESDBG_FILENAME); mir_free(tmp); bayesdb_fullpath_utf8 = mir_utf8encode(bayesdb_fullpath); if (sqlite3_open(bayesdb_fullpath_utf8, &bayesdbg) == SQLITE_OK) @@ -111,7 +111,7 @@ int get_token_count(int type) if (bayesdb == NULL) return 0; - mir_snprintf(q, SIZEOF(q), "SELECT COUNT(1) FROM %s", type == SPAM ? "spam" : "ham"); + mir_snprintf(q, _countof(q), "SELECT COUNT(1) FROM %s", type == SPAM ? "spam" : "ham"); sqlite3_prepare_v2(bayesdb, q, -1, &stmt, NULL); if (sqlite3_step(stmt) == SQLITE_ROW) { count = sqlite3_column_int(stmt, 0); @@ -166,7 +166,7 @@ int get_token_score(int type, char *token) if (bayesdb == NULL) return 0; - mir_snprintf(sql, SIZEOF(sql), "SELECT num FROM %s WHERE token=?", type == SPAM ? "spam" : "ham"); + mir_snprintf(sql, _countof(sql), "SELECT num FROM %s WHERE token=?", type == SPAM ? "spam" : "ham"); tokenhash(token, digest); sqlite3_prepare_v2(bayesdb, sql, -1, &stmt, NULL); sqlite3_bind_blob(stmt, 1, digest, 16, NULL); @@ -324,10 +324,10 @@ void learn(int type, TCHAR *msg) message = mir_u2a(msg); tok = strtok(message, DELIMS); - mir_snprintf(sql_counter, SIZEOF(sql_counter), "UPDATE stats SET value=value+1 WHERE key='%s'", type == SPAM ? "spam_msgcount" : "ham_msgcount"); - mir_snprintf(sql_select, SIZEOF(sql_select), "SELECT 1 FROM %s WHERE token=?", type == SPAM ? "spam" : "ham"); - mir_snprintf(sql_update, SIZEOF(sql_update), "UPDATE %s SET num=num+1 WHERE token=?", type ? "spam" : "ham"); - mir_snprintf(sql_insert, SIZEOF(sql_insert), "INSERT INTO %s VALUES(?, 1)", type ? "spam" : "ham"); + mir_snprintf(sql_counter, _countof(sql_counter), "UPDATE stats SET value=value+1 WHERE key='%s'", type == SPAM ? "spam_msgcount" : "ham_msgcount"); + mir_snprintf(sql_select, _countof(sql_select), "SELECT 1 FROM %s WHERE token=?", type == SPAM ? "spam" : "ham"); + mir_snprintf(sql_update, _countof(sql_update), "UPDATE %s SET num=num+1 WHERE token=?", type ? "spam" : "ham"); + mir_snprintf(sql_insert, _countof(sql_insert), "INSERT INTO %s VALUES(?, 1)", type ? "spam" : "ham"); #ifdef _DEBUG sqlite3_exec(bayesdbg, "BEGIN", NULL, NULL, NULL); #endif diff --git a/plugins/Spamotron/src/options.cpp b/plugins/Spamotron/src/options.cpp index 1b7a45727f..24183ba492 100644 --- a/plugins/Spamotron/src/options.cpp +++ b/plugins/Spamotron/src/options.cpp @@ -115,10 +115,10 @@ INT_PTR CALLBACK DlgProcOptionsMain(HWND optDlg, UINT msg, WPARAM wParam, LPARAM CheckDlgButton(optDlg, IDC_OPT_ADD_PERMANENTLY, _getOptB("AddPermanently", defaultAddPermanently) ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(optDlg, IDC_OPT_LOG_ACTIONS, _getOptB("LogActions", defaultLogActions) ? BST_CHECKED : BST_UNCHECKED); - SetDlgItemText(optDlg, IDC_OPT_IN_MSG_APPROVE_WORDLIST, _getOptS(buf, SIZEOF(buf), "ApproveOnMsgInWordlist", defaultApproveOnMsgInWordlist)); + SetDlgItemText(optDlg, IDC_OPT_IN_MSG_APPROVE_WORDLIST, _getOptS(buf, _countof(buf), "ApproveOnMsgInWordlist", defaultApproveOnMsgInWordlist)); SetDlgItemText(optDlg, IDC_OPT_MAX_MSG_CONTACT, _itot((unsigned int)_getOptD("MaxMsgContactCountPerDay", defaultMaxMsgContactCountPerDay), buf, 10)); SetDlgItemText(optDlg, IDC_OPT_MAX_SAME_MSG, _itot((unsigned int)_getOptD("MaxSameMsgCountPerDay", defaultMaxSameMsgCountPerDay), buf, 10)); - SetDlgItemText(optDlg, IDC_OPT_DONT_REPLY_MSG_WORDLIST, _getOptS(buf, SIZEOF(buf), "DontReplyMsgWordlist", defaultDontReplyMsgWordlist)); + SetDlgItemText(optDlg, IDC_OPT_DONT_REPLY_MSG_WORDLIST, _getOptS(buf, _countof(buf), "DontReplyMsgWordlist", defaultDontReplyMsgWordlist)); ///Individual protocols list ListView_SetExtendedListViewStyle(hProtocolsList, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT); @@ -199,8 +199,8 @@ INT_PTR CALLBACK DlgProcOptionsMain(HWND optDlg, UINT msg, WPARAM wParam, LPARAM _saveDlgItemInt(optDlg, IDC_OPT_MAX_SAME_MSG, "MaxSameMsgCountPerDay"); numProtocols = ListView_GetItemCount(hProtocolsList); for (i = 0; i < numProtocols; i++) { - ListView_GetItemText(hProtocolsList, i, 0, buf, SIZEOF(buf)); - //wcstombs(protoName, buf, SIZEOF(buf)); + ListView_GetItemText(hProtocolsList, i, 0, buf, _countof(buf)); + //wcstombs(protoName, buf, _countof(buf)); memset(protoOption, 0, sizeof(protoOption)); mir_strcat(protoOption, "proto_"); mir_strcat(protoOption, mir_u2a(buf)); @@ -520,7 +520,7 @@ INT_PTR CALLBACK DlgProcOptionsBayes(HWND optDlg, UINT msg, WPARAM wParam, LPARA if (!dbuf) return FALSE; GetDlgItemText(optDlg, IDC_OPT_BAYES_LEARNBOX, dbuf, len); - mir_snprintf(cbuf, SIZEOF(cbuf), "%0.04f", get_msg_score(dbuf)); + mir_snprintf(cbuf, _countof(cbuf), "%0.04f", get_msg_score(dbuf)); SetDlgItemText(optDlg, IDC_OPT_BAYES_LEARNBOX, _T("")); MessageBoxA(NULL, cbuf, Translate("Message score"), MB_OK); free(dbuf); diff --git a/plugins/Spamotron/src/spamotron.cpp b/plugins/Spamotron/src/spamotron.cpp index 89f62764ce..4101d8db4c 100644 --- a/plugins/Spamotron/src/spamotron.cpp +++ b/plugins/Spamotron/src/spamotron.cpp @@ -402,7 +402,7 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) case SPAMOTRON_MODE_MATH: a = (rand() % 10) + 1; b = (rand() % 10) + 1; - mir_sntprintf(mexpr, SIZEOF(mexpr), _T("%d + %d"), a, b); + mir_sntprintf(mexpr, _countof(mexpr), _T("%d + %d"), a, b); if (dbei->eventType == EVENTTYPE_AUTHREQUEST) _getOptS(challengeW, maxmsglen, "AuthChallengeMath", defaultAuthChallengeMath); else diff --git a/plugins/Spamotron/src/utils.cpp b/plugins/Spamotron/src/utils.cpp index 9e54383800..74e3f96bd5 100644 --- a/plugins/Spamotron/src/utils.cpp +++ b/plugins/Spamotron/src/utils.cpp @@ -370,7 +370,7 @@ TCHAR* ReplaceVarsNum(TCHAR *dst, unsigned int len, int num) re = pcre16_compile(regex, 0, &error, &erroroffs, NULL); if (re == NULL) return FALSE; // [TODO] and log some error - _getOptS(response, SIZEOF(response), "Response", defaultResponse); + _getOptS(response, _countof(response), "Response", defaultResponse); ttmp = _tcstok(response, _T("\r\n")); for (i = 0; ttmp != NULL; i ++) { @@ -428,7 +428,7 @@ int _notify(MCONTACT hContact, BYTE type, TCHAR *message, TCHAR *origmessage) { char *tmp, *tmporig; TCHAR msg[MAX_BUFFER_LENGTH]; - mir_sntprintf(msg, SIZEOF(msg), message, CONTACT_NAME(hContact)); + mir_sntprintf(msg, _countof(msg), message, CONTACT_NAME(hContact)); if (_getOptB("LogActions", defaultLogActions)) { tmp = mir_u2a(msg); @@ -468,9 +468,9 @@ int LogToSystemHistory(char *message, char *origmessage) dbei.szModule = PLUGIN_NAME; dbei.pBlob = (PBYTE)msg; if (origmessage) - dbei.cbBlob = (1 + mir_snprintf(msg, SIZEOF(msg), "%s: %s%s %s: %s", PLUGIN_NAME, message, DOT(message), Translate("Their message was"), origmessage)); + dbei.cbBlob = (1 + mir_snprintf(msg, _countof(msg), "%s: %s%s %s: %s", PLUGIN_NAME, message, DOT(message), Translate("Their message was"), origmessage)); else - dbei.cbBlob = (1 + mir_snprintf(msg, SIZEOF(msg), "%s: %s%s", PLUGIN_NAME, message, DOT(message))); + dbei.cbBlob = (1 + mir_snprintf(msg, _countof(msg), "%s: %s%s", PLUGIN_NAME, message, DOT(message))); dbei.eventType = EVENTTYPE_MESSAGE; dbei.flags = DBEF_READ; db_event_add(NULL, &dbei); -- cgit v1.2.3