summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-09-09 19:55:34 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-09-09 19:55:34 +0000
commitc4a2507e68bd2040e5944ccbbafb87ea6196fe06 (patch)
tree393c41cb88601434d8f47d3ebb93d163de95a470
parentabb55ccf0e13f077d976777c6e16b9a7bc889821 (diff)
- memory corruption in [img] button;
- code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@6037 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--plugins/TabSRMM/src/chat/clist.cpp2
-rw-r--r--plugins/TabSRMM/src/chat/log.cpp4
-rw-r--r--plugins/TabSRMM/src/chat/window.cpp4
-rw-r--r--plugins/TabSRMM/src/modplus.cpp159
-rw-r--r--plugins/TabSRMM/src/msgdialog.cpp2
5 files changed, 77 insertions, 94 deletions
diff --git a/plugins/TabSRMM/src/chat/clist.cpp b/plugins/TabSRMM/src/chat/clist.cpp
index 3afb600074..fc233ec946 100644
--- a/plugins/TabSRMM/src/chat/clist.cpp
+++ b/plugins/TabSRMM/src/chat/clist.cpp
@@ -223,7 +223,7 @@ BOOL CList_AddEvent(HANDLE hContact, HICON Icon, HANDLE event, int type, const T
if (!fmt || lstrlen(fmt) < 1 || lstrlen(fmt) > 2000)
return FALSE;
- TCHAR* szBuf = (TCHAR*)alloca(4096 * sizeof(TCHAR));
+ TCHAR* szBuf = (TCHAR*)_alloca(4096 * sizeof(TCHAR));
va_list marker;
va_start(marker, fmt);
diff --git a/plugins/TabSRMM/src/chat/log.cpp b/plugins/TabSRMM/src/chat/log.cpp
index 96c049f032..14b9236cd0 100644
--- a/plugins/TabSRMM/src/chat/log.cpp
+++ b/plugins/TabSRMM/src/chat/log.cpp
@@ -87,7 +87,7 @@ static int Log_AppendIEView(LOGSTREAMDATA* streamData, BOOL simpleMode, TCHAR **
{
va_list va;
int lineLen, textCharsCount=0;
- TCHAR* line = (TCHAR*)alloca( 8001 * sizeof(TCHAR));
+ TCHAR* line = (TCHAR*)_alloca( 8001 * sizeof(TCHAR));
TCHAR* d;
MODULEINFO *mi = MM_FindModule(streamData->si->pszModule);
@@ -519,7 +519,7 @@ static int Log_AppendRTF(LOGSTREAMDATA* streamData, BOOL simpleMode, char **buff
va_list va;
int textCharsCount = 0;
char *d;
- TCHAR *line = (TCHAR*)alloca(8001 * sizeof(TCHAR));
+ TCHAR *line = (TCHAR*)_alloca(8001 * sizeof(TCHAR));
va_start(va, fmt);
int lineLen = mir_vsntprintf(line, 8000, fmt, va);
diff --git a/plugins/TabSRMM/src/chat/window.cpp b/plugins/TabSRMM/src/chat/window.cpp
index 01dac55bef..be1b656a16 100644
--- a/plugins/TabSRMM/src/chat/window.cpp
+++ b/plugins/TabSRMM/src/chat/window.cpp
@@ -2662,7 +2662,7 @@ LABEL_SHOWWINDOW:
ClientToScreen(((LPNMHDR)lParam)->hwndFrom, &pt);
// fixing stuff for searches
- TCHAR *pszWord = (TCHAR*)alloca(8192);
+ TCHAR *pszWord = (TCHAR*)_alloca(8192);
pszWord[0] = '\0';
POINTL ptl = { pt.x, pt.y };
ScreenToClient(GetDlgItem(hwndDlg, IDC_CHAT_LOG), (LPPOINT)&ptl);
@@ -2972,7 +2972,7 @@ LABEL_SHOWWINDOW:
if (g_Settings.bDoubleClick4Privat ? GetKeyState(VK_SHIFT) & 0x8000 : !(GetKeyState(VK_SHIFT) & 0x8000)) {
LRESULT lResult = (LRESULT)SendMessage(GetDlgItem(hwndDlg, IDC_CHAT_MESSAGE), EM_GETSEL, 0, 0);
int start = LOWORD(lResult);
- TCHAR* pszName = (TCHAR*)alloca(sizeof(TCHAR) * (lstrlen(ui->pszUID) + 3));
+ TCHAR* pszName = (TCHAR*)_alloca(sizeof(TCHAR) * (lstrlen(ui->pszUID) + 3));
if (start == 0)
mir_sntprintf(pszName, lstrlen(ui->pszUID) + 3, _T("%s: "), ui->pszUID);
else
diff --git a/plugins/TabSRMM/src/modplus.cpp b/plugins/TabSRMM/src/modplus.cpp
index ab30dd53d6..b616276f0e 100644
--- a/plugins/TabSRMM/src/modplus.cpp
+++ b/plugins/TabSRMM/src/modplus.cpp
@@ -83,116 +83,99 @@ static int RegisterCustomButton(WPARAM wParam,LPARAM lParam)
static int CustomButtonPressed(WPARAM wParam,LPARAM lParam)
{
CustomButtonClickData *cbcd=(CustomButtonClickData *)lParam;
+ if ( strcmp(cbcd->pszModule,"Tabmodplus") || cbcd->dwButtonId != 1)
+ return 0;
- CHARRANGE cr;
- TCHAR* pszMenu[256]={0};//=NULL;
- int i=0;
- TCHAR* pszText = (TCHAR*)_T("");
- TCHAR* pszFormatedText=NULL;
- UINT textlenght=0;
- BBButton bbd={0};
-
- int state=0;
-
- if ( strcmp(cbcd->pszModule,"Tabmodplus")||cbcd->dwButtonId!=1 ) return (0);
-
- bbd.cbSize=sizeof(BBButton);
- bbd.dwButtonID=1;
+ BBButton bbd = { sizeof(bbd) };
+ bbd.dwButtonID = 1;
bbd.pszModuleName = (char *)"Tabmodplus";
CallService(MS_BB_GETBUTTONSTATE, wParam, (LPARAM)&bbd);
+ TCHAR *pszText = _T("");
+ CHARRANGE cr;
cr.cpMin = cr.cpMax = 0;
SendDlgItemMessage(cbcd->hwndFrom,IDC_MESSAGE, EM_EXGETSEL, 0, (LPARAM)&cr);
- textlenght=cr.cpMax-cr.cpMin;
- if ( textlenght ) {
+ UINT textlenght = cr.cpMax - cr.cpMin;
+ if (textlenght) {
pszText = (TCHAR*)mir_alloc((textlenght+1)*sizeof(TCHAR));
ZeroMemory(pszText,(textlenght+1)*sizeof(TCHAR));
SendDlgItemMessage(cbcd->hwndFrom, IDC_MESSAGE,EM_GETSELTEXT, 0, (LPARAM)pszText);
}
- if ( cbcd->flags & BBCF_RIGHTBUTTON )
- state=1;
- else if ( textlenght )
+ int state = 0;
+ if (cbcd->flags & BBCF_RIGHTBUTTON)
+ state = 1;
+ else if (textlenght)
state = 2;
- else if ( bbd.bbbFlags & BBSF_PUSHED )
+ else if (bbd.bbbFlags & BBSF_PUSHED)
state = 3;
else
state = 4;
+ TCHAR *pszFormatedText = NULL, *pszMenu[256] = {0};
+
+ size_t bufSize;
+
switch ( state ) {
- case 1:
- {
- int res=0;
- int menunum;
- int menulimit;
- HMENU hMenu=NULL;
-
- menulimit = M.GetByte("tabmodplus","MenuCount", 0);
- if ( menulimit ) {
- hMenu = CreatePopupMenu();
- //pszMenu=mir_alloc(menulimit*sizeof(TCHAR*));
- } else break;
- for ( menunum=0;menunum<menulimit;menunum++ ) {
- pszMenu[menunum]=getMenuEntry(menunum);
- AppendMenu(hMenu, MF_STRING,menunum+1, pszMenu[menunum]);
- }
- res = TrackPopupMenu(hMenu, TPM_RETURNCMD, cbcd->pt.x, cbcd->pt.y, 0, cbcd->hwndFrom, NULL);
- if ( res==0 ) break;
-
- pszFormatedText = (TCHAR*)mir_alloc((textlenght+lstrlen(pszMenu[res-1])+2)*sizeof(TCHAR));
- ZeroMemory(pszFormatedText,(textlenght+lstrlen(pszMenu[res-1])+2)*sizeof(TCHAR));
-
- mir_sntprintf(pszFormatedText,(textlenght+lstrlen(pszMenu[res-1])+2)*sizeof(TCHAR),pszMenu[res-1],pszText);
-
- }break;
- case 2:
- {
- pszFormatedText = (TCHAR*)mir_alloc((textlenght+12)*sizeof(TCHAR));
- ZeroMemory(pszFormatedText,(textlenght+12)*sizeof(TCHAR));
-
- SendDlgItemMessage(cbcd->hwndFrom, IDC_MESSAGE,EM_GETSELTEXT, 0, (LPARAM)pszText);
- mir_sntprintf(pszFormatedText,(textlenght+12)*sizeof(TCHAR),_T("[img]%s[/img]"),pszText);
-
- bbd.ptszTooltip=0;
- bbd.hIcon=0;
- bbd.bbbFlags=BBSF_RELEASED;
- CallService(MS_BB_SETBUTTONSTATE, wParam, (LPARAM)&bbd);
- }break;
-
- case 3:
- {
- pszFormatedText = (TCHAR*)mir_alloc(6*sizeof(TCHAR));
- ZeroMemory(pszFormatedText,6*sizeof(TCHAR));
-
- mir_sntprintf(pszFormatedText,6*sizeof(TCHAR),_T("%s"),_T("[img]"));
-
- bbd.ptszTooltip = TranslateT("Insert [img] tag / surround selected text with [img][/img]");
- CallService(MS_BB_SETBUTTONSTATE, wParam, (LPARAM)&bbd);
-
- }break;
- case 4:
- {
-
- pszFormatedText = (TCHAR*)mir_alloc(7*sizeof(TCHAR));
- ZeroMemory(pszFormatedText,7*sizeof(TCHAR));
- mir_sntprintf(pszFormatedText,7*sizeof(TCHAR),_T("%s"),_T("[/img]"));
-
- bbd.ptszTooltip = TranslateT("Insert [img] tag / surround selected text with [img][/img]");
- CallService(MS_BB_SETBUTTONSTATE, wParam, (LPARAM)&bbd);
-
- }break;
+ case 1:
+ {
+ int menulimit = M.GetByte("tabmodplus","MenuCount", 0);
+ if (menulimit == 0)
+ break;
+
+ HMENU hMenu = CreatePopupMenu();
+
+ for (int menunum=0; menunum < menulimit; menunum++) {
+ pszMenu[menunum] = getMenuEntry(menunum);
+ AppendMenu(hMenu, MF_STRING,menunum+1, pszMenu[menunum]);
+ }
+ int res = TrackPopupMenu(hMenu, TPM_RETURNCMD, cbcd->pt.x, cbcd->pt.y, 0, cbcd->hwndFrom, NULL);
+ if (res == 0)
+ break;
+
+ bufSize = textlenght + lstrlen(pszMenu[res-1]) + 2;
+ pszFormatedText = (TCHAR*)_alloca(bufSize*sizeof(TCHAR));
+ mir_sntprintf(pszFormatedText, bufSize, pszMenu[res-1], pszText);
+ }
+ break;
+
+ case 2:
+ SendDlgItemMessage(cbcd->hwndFrom, IDC_MESSAGE, EM_GETSELTEXT, 0, (LPARAM)pszText);
+
+ bufSize = textlenght+12;
+ pszFormatedText = (TCHAR*)_alloca(bufSize*sizeof(TCHAR));
+ mir_sntprintf(pszFormatedText, bufSize*sizeof(TCHAR), _T("[img]%s[/img]"), pszText);
+
+ bbd.ptszTooltip = 0;
+ bbd.hIcon = 0;
+ bbd.bbbFlags = BBSF_RELEASED;
+ CallService(MS_BB_SETBUTTONSTATE, wParam, (LPARAM)&bbd);
+ break;
+
+ case 3:
+ pszFormatedText = _T("[img]");
+
+ bbd.ptszTooltip = TranslateT("Insert [img] tag / surround selected text with [img][/img]");
+ CallService(MS_BB_SETBUTTONSTATE, wParam, (LPARAM)&bbd);
+ break;
+
+ case 4:
+ pszFormatedText = _T("[/img]");
+
+ bbd.ptszTooltip = TranslateT("Insert [img] tag / surround selected text with [img][/img]");
+ CallService(MS_BB_SETBUTTONSTATE, wParam, (LPARAM)&bbd);
+ break;
}
- while ( pszMenu[i] ) {
+ for (int i=0; pszMenu[i]; i++)
mir_free(pszMenu[i]);
- i++;
- }
- if ( pszFormatedText ) SendDlgItemMessage(cbcd->hwndFrom, IDC_MESSAGE, EM_REPLACESEL, TRUE, (LPARAM)pszFormatedText);
+ if ( pszFormatedText )
+ SendDlgItemMessage(cbcd->hwndFrom, IDC_MESSAGE, EM_REPLACESEL, TRUE, (LPARAM)pszFormatedText);
- if ( textlenght ) mir_free(pszText);
- if ( pszFormatedText ) mir_free(pszFormatedText);
- return (1);
+ if ( textlenght )
+ mir_free(pszText);
+ return 1;
}
diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp
index 87f3170f4c..ec719312e4 100644
--- a/plugins/TabSRMM/src/msgdialog.cpp
+++ b/plugins/TabSRMM/src/msgdialog.cpp
@@ -1317,7 +1317,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
if (dat->hContact && dat->szProto != NULL) {
dat->wStatus = db_get_w(dat->hContact, dat->szProto, "Status", ID_STATUS_OFFLINE);
- mir_sntprintf(dat->szStatus, SIZEOF(dat->szStatus), _T("%s"), (char *)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, dat->szProto == NULL ? ID_STATUS_OFFLINE : dat->wStatus, GSMDF_TCHAR));
+ _tcsncpy_s(dat->szStatus, SIZEOF(dat->szStatus), pcli->pfnGetStatusModeDescription(dat->szProto == NULL ? ID_STATUS_OFFLINE : dat->wStatus, 0), _TRUNCATE);
}
else dat->wStatus = ID_STATUS_OFFLINE;