summaryrefslogtreecommitdiff
path: root/plugins/TabSRMM
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-12-24 15:03:40 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-12-24 15:03:40 +0000
commit0851c3965879663c41cfe435d1b320ba68cf873a (patch)
tree9959d614cfb7923654842a577a48d38128fafcc9 /plugins/TabSRMM
parent7bf458c314a911bedabc7c987b7ab352153248c1 (diff)
fix for crash in RTF parser
git-svn-id: http://svn.miranda-ng.org/main/trunk@2830 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/TabSRMM')
-rw-r--r--plugins/TabSRMM/src/chat/message.cpp19
-rw-r--r--plugins/TabSRMM/src/chat/window.cpp67
2 files changed, 39 insertions, 47 deletions
diff --git a/plugins/TabSRMM/src/chat/message.cpp b/plugins/TabSRMM/src/chat/message.cpp
index 71fbba7276..48ccf0ff64 100644
--- a/plugins/TabSRMM/src/chat/message.cpp
+++ b/plugins/TabSRMM/src/chat/message.cpp
@@ -84,13 +84,10 @@ static int ReadInteger(const char* p, int* result)
TCHAR* Chat_DoRtfToTags(char* pszText, SESSION_INFO* si)
{
- char *p1;
- int* pIndex;
int i, iRemoveChars, cp = CP_ACP;
char InsertThis[50];
BOOL bJustRemovedRTF = TRUE;
BOOL bTextHasStarted = FALSE;
- TCHAR *ptszResult; //, *d;
int iUcMode = 0;
if (!pszText)
@@ -98,20 +95,20 @@ TCHAR* Chat_DoRtfToTags(char* pszText, SESSION_INFO* si)
// create an index of colors in the module and map them to
// corresponding colors in the RTF color table
- pIndex = (int *)mir_alloc(sizeof(int) * MM_FindModule(si->pszModule)->nColorCount);
+ mir_ptr<int> pIndex((int*)mir_alloc(sizeof(int) * MM_FindModule(si->pszModule)->nColorCount));
for (i=0; i < MM_FindModule(si->pszModule)->nColorCount ; i++)
pIndex[i] = -1;
CreateColorMap(pszText, pIndex, si);
// scan the file for rtf commands and remove or parse them
- p1 = strstr(pszText, "\\pard");
+ char *p1 = strstr(pszText, "\\ltrpar");
if (p1 == NULL) {
- mir_free(pIndex);
- return FALSE;
+ if ((p1 = strstr(pszText, "\\pard")) == NULL)
+ return FALSE;
+ p1 += 5;
}
-
- p1 += 5;
+ else p1 += 7;
MoveMemory(pszText, p1, lstrlenA(p1) + 1);
p1 = pszText;
@@ -293,9 +290,7 @@ TCHAR* Chat_DoRtfToTags(char* pszText, SESSION_INFO* si)
} else p1++;
}
- mir_free(pIndex);
- ptszResult = mir_utf8decodeW(pszText);
- return ptszResult;
+ return mir_utf8decodeW(pszText);
}
static DWORD CALLBACK Chat_Message_StreamCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb)
diff --git a/plugins/TabSRMM/src/chat/window.cpp b/plugins/TabSRMM/src/chat/window.cpp
index 6d85d6244a..4f86fe2654 100644
--- a/plugins/TabSRMM/src/chat/window.cpp
+++ b/plugins/TabSRMM/src/chat/window.cpp
@@ -3153,44 +3153,41 @@ LABEL_SHOWWINDOW:
ShowWindow(dat->pContainer->hwnd, SW_MINIMIZE);
return FALSE;
- case IDOK: {
- char* pszRtf;
- TCHAR* ptszText/*, *p1*/;
- MODULEINFO* mi;
- bool fSound = true;
+ case IDOK:
+ if (GetSendButtonState(hwndDlg) != PBS_DISABLED) {
+ MODULEINFO *mi = MM_FindModule(si->pszModule);
- if (GetSendButtonState(hwndDlg) == PBS_DISABLED)
- break;
+ mir_ptr<char> pszRtf( Chat_Message_GetFromStream(hwndDlg, si));
+ SM_AddCommand(si->ptszID, si->pszModule, pszRtf);
+
+ mir_ptr<TCHAR> ptszText( Chat_DoRtfToTags(pszRtf, si));
+ if ((TCHAR*)ptszText == NULL)
+ break;
+
+ DoTrimMessage(ptszText);
- mi = MM_FindModule(si->pszModule);
-
- pszRtf = Chat_Message_GetFromStream(hwndDlg, si);
- SM_AddCommand(si->ptszID, si->pszModule, pszRtf);
- ptszText = Chat_DoRtfToTags(pszRtf, si);
- DoTrimMessage(ptszText);
-
- if (mi && mi->bAckMsg) {
- Utils::enableDlgControl(hwndDlg, IDC_CHAT_MESSAGE, FALSE);
- SendDlgItemMessage(hwndDlg, IDC_CHAT_MESSAGE, EM_SETREADONLY, TRUE, 0);
- } else SendDlgItemMessage(hwndDlg, IDC_CHAT_MESSAGE, WM_SETTEXT, 0, (LPARAM)_T(""));
-
- Utils::enableDlgControl(hwndDlg, IDOK, FALSE);
-
- if (ptszText[0] == '/' || si->iType == GCW_SERVER)
- fSound = false;
- DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_MESSAGE, NULL, ptszText, 0);
- mi->idleTimeStamp = time(0);
- mi->lastIdleCheck = 0;
- SM_BroadcastMessage(si->pszModule, GC_UPDATESTATUSBAR, 0, 1, TRUE);
- if (dat && dat->pContainer) {
- if (fSound && !nen_options.iNoSounds && !(dat->pContainer->dwFlags & CNT_NOSOUND))
- SkinPlaySound("ChatSent");
+ if (mi && mi->bAckMsg) {
+ Utils::enableDlgControl(hwndDlg, IDC_CHAT_MESSAGE, FALSE);
+ SendDlgItemMessage(hwndDlg, IDC_CHAT_MESSAGE, EM_SETREADONLY, TRUE, 0);
+ }
+ else SendDlgItemMessage(hwndDlg, IDC_CHAT_MESSAGE, WM_SETTEXT, 0, (LPARAM)_T(""));
+
+ Utils::enableDlgControl(hwndDlg, IDOK, FALSE);
+
+ bool fSound = true;
+ if (ptszText[0] == '/' || si->iType == GCW_SERVER)
+ fSound = false;
+ DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_MESSAGE, NULL, ptszText, 0);
+ mi->idleTimeStamp = time(0);
+ mi->lastIdleCheck = 0;
+ SM_BroadcastMessage(si->pszModule, GC_UPDATESTATUSBAR, 0, 1, TRUE);
+ if (dat && dat->pContainer)
+ if (fSound && !nen_options.iNoSounds && !(dat->pContainer->dwFlags & CNT_NOSOUND))
+ SkinPlaySound("ChatSent");
+
+ SetFocus(GetDlgItem(hwndDlg, IDC_CHAT_MESSAGE));
}
- mir_free(pszRtf);
- mir_free(ptszText);
- SetFocus(GetDlgItem(hwndDlg, IDC_CHAT_MESSAGE));
- }
- break;
+ break;
case IDC_SHOWNICKLIST:
if (!IsWindowEnabled(GetDlgItem(hwndDlg, IDC_SHOWNICKLIST)))