From a1a932ba54cd0cebb1b7cc7088fc4261638e4f86 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 8 Jul 2012 11:41:27 +0000 Subject: GCDNF_NOCACHE, memleaks & crazy code git-svn-id: http://svn.miranda-ng.org/main/trunk@844 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/AvatarHistory/src/popup.cpp | 36 +++++++++++----------- plugins/Clist_mw/clistsettings.cpp | 2 +- plugins/Utils/mir_buffer.h | 60 ++++++++++++++++++------------------- src/modules/clist/clistsettings.cpp | 28 +++++++++-------- 4 files changed, 63 insertions(+), 63 deletions(-) diff --git a/plugins/AvatarHistory/src/popup.cpp b/plugins/AvatarHistory/src/popup.cpp index dc03ee783d..a27917de43 100644 --- a/plugins/AvatarHistory/src/popup.cpp +++ b/plugins/AvatarHistory/src/popup.cpp @@ -1,4 +1,4 @@ -/* +/* Copyright (C) 2005 Ricardo Pescuma Domenecci This is free software; you can redistribute it and/or @@ -14,7 +14,7 @@ Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this file; see the file license.txt. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. +Boston, MA 02111-1307, USA. */ @@ -44,7 +44,7 @@ static LRESULT CALLBACK DumbPopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, void InitPopups() { // window needed for popup commands - hPopupWindow = CreateWindowEx(WS_EX_TOOLWINDOW, _T("static"), _T(MODULE_NAME) _T("_PopupWindow"), + hPopupWindow = CreateWindowEx(WS_EX_TOOLWINDOW, _T("static"), _T(MODULE_NAME) _T("_PopupWindow"), 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, HWND_DESKTOP, NULL, hInst, NULL); SetWindowLong(hPopupWindow, GWLP_WNDPROC, (LONG_PTR)PopupWndProc); @@ -88,21 +88,21 @@ typedef struct { void* plugin_data; HICON hIcon; -} +} PopupDataType; // Show an popup -void ShowPopupEx(HANDLE hContact, const TCHAR *title, const TCHAR *description, +void ShowPopupEx(HANDLE hContact, const TCHAR *title, const TCHAR *description, void *plugin_data, int type, const Options *op) { - if(ServiceExists(MS_POPUP_ADDPOPUPT)) + if(ServiceExists(MS_POPUP_ADDPOPUPT)) { // Make popup POPUPDATAT ppd = {0}; - ppd.lchContact = hContact; + ppd.lchContact = hContact; ppd.lchIcon = createProtoOverlayedIcon(hContact); - + ppd.PluginData = mir_alloc(sizeof(PopupDataType)); ((PopupDataType*)ppd.PluginData)->plugin_data = plugin_data; ((PopupDataType*)ppd.PluginData)->hIcon = ppd.lchIcon; @@ -110,7 +110,7 @@ void ShowPopupEx(HANDLE hContact, const TCHAR *title, const TCHAR *description, if (title != NULL) lstrcpyn(ppd.lptzContactName, title, MAX_REGS(ppd.lptzContactName)); else if (hContact != NULL) - lstrcpyn(ppd.lptzContactName, (TCHAR *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR | GCDNF_NOCACHE), + lstrcpyn(ppd.lptzContactName, (TCHAR *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR), MAX_REGS(ppd.lptzContactName)); if (description != NULL) @@ -148,10 +148,10 @@ void ShowPopupEx(HANDLE hContact, const TCHAR *title, const TCHAR *description, { ppd.PluginWindowProc = DumbPopupDlgProc; } - + if (type == POPUP_TYPE_NORMAL || type == POPUP_TYPE_TEST) { - switch (op->popup_delay_type) + switch (op->popup_delay_type) { case POPUP_DELAY_CUSTOM: ppd.iSeconds = opts.popup_timeout; @@ -177,7 +177,7 @@ void ShowPopupEx(HANDLE hContact, const TCHAR *title, const TCHAR *description, } else { - MessageBox(NULL, description, title ? title : (TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR), + MessageBox(NULL, description, title ? title : (TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR), MB_OK); } @@ -186,7 +186,7 @@ void ShowPopupEx(HANDLE hContact, const TCHAR *title, const TCHAR *description, // Handle to the hidden windows to handle actions for popup clicks // wParam has the number of MOTD in case of WMU_SHOW_MOTD_DETAILS -LRESULT CALLBACK PopupWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK PopupWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { if (uMsg == WMU_ACTION) { @@ -218,7 +218,7 @@ static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPA return TRUE; } - case WM_CONTEXTMENU: + case WM_CONTEXTMENU: { PopupDataType* popup = (PopupDataType*)PUGetPluginData(hWnd); PostMessage(hPopupWindow, WMU_ACTION, (WPARAM)popup->plugin_data, opts.popup_right_click_action); @@ -229,7 +229,7 @@ static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPA return TRUE; } - case UM_FREEPLUGINDATA: + case UM_FREEPLUGINDATA: { PopupDataType* popup = (PopupDataType*)PUGetPluginData(hWnd); if ((INT_PTR)popup != CALLSERVICE_NOTFOUND) @@ -255,13 +255,13 @@ static LRESULT CALLBACK DumbPopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, return TRUE; } - case WM_CONTEXTMENU: + case WM_CONTEXTMENU: { PUDeletePopUp(hWnd); return TRUE; } - case UM_FREEPLUGINDATA: + case UM_FREEPLUGINDATA: { PopupDataType* popup = (PopupDataType*)PUGetPluginData(hWnd); if ((INT_PTR)popup != CALLSERVICE_NOTFOUND) @@ -275,5 +275,3 @@ static LRESULT CALLBACK DumbPopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, return DefWindowProc(hWnd, message, wParam, lParam); } - - diff --git a/plugins/Clist_mw/clistsettings.cpp b/plugins/Clist_mw/clistsettings.cpp index ecdb3d8089..f18a4452f2 100644 --- a/plugins/Clist_mw/clistsettings.cpp +++ b/plugins/Clist_mw/clistsettings.cpp @@ -112,7 +112,7 @@ void CheckPDNCE(ClcCacheEntryBase *_pdnce) else { if (pdnce->isUnknown&&pdnce->szProto&&pdnce->protoNotExists == TRUE&&OnModulesLoadedCalled) { pdnce->protoNotExists = FALSE; - mir_free(pdnce->tszName); + mir_free(pdnce->tszName); pdnce->tszName = GetNameForContact(pdnce->hContact,0,&pdnce->isUnknown); } } diff --git a/plugins/Utils/mir_buffer.h b/plugins/Utils/mir_buffer.h index 3a1f30d558..2b74cb7d11 100644 --- a/plugins/Utils/mir_buffer.h +++ b/plugins/Utils/mir_buffer.h @@ -1,4 +1,4 @@ -/* +/* Copyright (C) 2005-2009 Ricardo Pescuma Domenecci This is free software; you can redistribute it and/or @@ -14,7 +14,7 @@ Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this file; see the file license.txt. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. +Boston, MA 02111-1307, USA. */ @@ -114,7 +114,7 @@ static void __bcopy(char *dest, const WCHAR *orig, size_t len) template -class Buffer +class Buffer { public: size_t len; @@ -122,7 +122,7 @@ class Buffer Buffer() : str(NULL), size(0), len(0) { - alloc(1); + alloc(1); pack(); } @@ -145,13 +145,13 @@ class Buffer free(); } - void pack() + void pack() { if (str != NULL) memset(&str[len], 0, sizeof(str[len])); } - void alloc(size_t total) + void alloc(size_t total) { if (total > size) { @@ -173,7 +173,7 @@ class Buffer } } - void clear() + void clear() { len = 0; pack(); @@ -308,7 +308,7 @@ class Buffer size_t oldLen = end - start; if (oldLen < appLen) alloc(len + appLen - oldLen + 1); - + if (end < len && oldLen != appLen) memmove(&str[start + appLen], &str[end], (len - end) * sizeof(T)); memmove(&str[start], app, appLen * sizeof(T)); @@ -348,7 +348,7 @@ class Buffer } } - T *appender(size_t appLen) + T *appender(size_t appLen) { alloc(len + appLen + 1); T *ret = &str[len]; @@ -356,18 +356,18 @@ class Buffer return ret; } - T *lock(size_t maxSize) + T *lock(size_t maxSize) { alloc(len + maxSize + 1); return &str[len]; } - void release() + void release() { len += max(__blen(&str[len]), size - len - 1); } - T *detach() + T *detach() { T *ret = str; str = NULL; @@ -375,29 +375,29 @@ class Buffer return ret; } - void trimRight() + void trimRight() { if (str == NULL) return; int e; - for(e = len-1; e >= 0 && (str[e] == (T)' ' - || str[e] == (T)'\t' - || str[e] == (T)'\r' + for(e = len-1; e >= 0 && (str[e] == (T)' ' + || str[e] == (T)'\t' + || str[e] == (T)'\r' || str[e] == (T)'\n'); e--) ; len = e+1; pack(); } - void trimLeft() + void trimLeft() { if (str == NULL) return; int s; - for(s = 0; str[s] == (T)' ' - || str[s] == (T)'\t' - || str[s] == (T)'\r' + for(s = 0; str[s] == (T)' ' + || str[s] == (T)'\t' + || str[s] == (T)'\r' || str[s] == (T)'\n'; s++) ; if (s > 0) { @@ -407,45 +407,45 @@ class Buffer pack(); } - void trim() + void trim() { trimRight(); trimLeft(); } - Buffer& operator+=(const char *txt) + Buffer& operator+=(const char *txt) { append(txt); return *this; } - Buffer& operator+=(const WCHAR *txt) + Buffer& operator+=(const WCHAR *txt) { append(txt); return *this; } - Buffer& operator+=(const Buffer &txt) + Buffer& operator+=(const Buffer &txt) { append(txt); return *this; } - Buffer& operator=(const char *txt) + Buffer& operator=(const char *txt) { clear(); append(txt); return *this; } - Buffer& operator=(const WCHAR *txt) + Buffer& operator=(const WCHAR *txt) { clear(); append(txt); return *this; } - Buffer& operator=(const Buffer &txt) + Buffer& operator=(const Buffer &txt) { clear(); append(txt); @@ -482,7 +482,7 @@ static void ReplaceVars(Buffer *buffer, HANDLE hContact, TCHAR **variable size_t foundLen = i - j + 1; if (foundLen == 9 && _tcsncmp(&buffer->str[j], _T("%contact%"), 9) == 0) { - buffer->replace(j, i + 1, (TCHAR *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) hContact, GCDNF_TCHAR | GCDNF_NOCACHE)); + buffer->replace(j, i + 1, (TCHAR *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) hContact, GCDNF_TCHAR)); } else if (foundLen == 6 && _tcsncmp(&buffer->str[j], _T("%date%"), 6) == 0) { @@ -512,7 +512,7 @@ static void ReplaceVars(Buffer *buffer, HANDLE hContact, TCHAR **variable if (i == 0) break; } - else if (buffer->str[i] == _T('\\') && i+1 <= buffer->len-1 && buffer->str[i+1] == _T('n')) + else if (buffer->str[i] == _T('\\') && i+1 <= buffer->len-1 && buffer->str[i+1] == _T('n')) { buffer->str[i] = _T('\r'); buffer->str[i+1] = _T('\n'); @@ -524,7 +524,7 @@ static void ReplaceVars(Buffer *buffer, HANDLE hContact, TCHAR **variable static void ReplaceTemplate(Buffer *out, HANDLE hContact, TCHAR *templ, TCHAR **vars, int numVars) { - if (ServiceExists(MS_VARS_FORMATSTRING)) + if (ServiceExists(MS_VARS_FORMATSTRING)) { TCHAR *tmp = variables_parse_ex(templ, NULL, hContact, vars, numVars); if (tmp != NULL) diff --git a/src/modules/clist/clistsettings.cpp b/src/modules/clist/clistsettings.cpp index 8b39b3cfd9..4e25504853 100644 --- a/src/modules/clist/clistsettings.cpp +++ b/src/modules/clist/clistsettings.cpp @@ -154,17 +154,18 @@ TCHAR* fnGetContactDisplayName(HANDLE hContact, int mode) INT_PTR GetContactDisplayName(WPARAM wParam, LPARAM lParam) { + static char retVal[200]; ClcCacheEntryBase* cacheEntry = NULL; - char *buffer; HANDLE hContact = (HANDLE)wParam; if (lParam & GCDNF_UNICODE) return (INT_PTR)cli.pfnGetContactDisplayName(hContact, lParam & ~GCDNF_UNICODE); - if (lParam != GCDNF_NOMYHANDLE) { + if (lParam & GCDNF_NOCACHE) + lParam &= ~GCDNF_NOCACHE; + else if (lParam != GCDNF_NOMYHANDLE) { cacheEntry = cli.pfnGetCacheEntry(hContact); if (cacheEntry->tszName) { - static char retVal[200]; strncpy(retVal, _T2A(cacheEntry->tszName), SIZEOF(retVal)); return (INT_PTR)retVal; } @@ -178,27 +179,28 @@ INT_PTR GetContactDisplayName(WPARAM wParam, LPARAM lParam) ci.dwFlag = ((lParam == GCDNF_NOMYHANDLE) ? CNF_DISPLAYNC : CNF_DISPLAY) | CNF_TCHAR; if ( !CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci)) { if (ci.type == CNFT_ASCIIZ) { + strncpy(retVal, _T2A(ci.pszVal), SIZEOF(retVal)); if (cacheEntry == NULL) { - buffer = mir_u2a(ci.pszVal); mir_free(ci.pszVal); - return (INT_PTR) buffer; + return (INT_PTR)mir_strdup(retVal); } cacheEntry->tszName = ci.pszVal; - return (INT_PTR)cacheEntry->tszName; + return (INT_PTR)retVal; } if (ci.type == CNFT_DWORD) { - buffer = (char*)mir_alloc(15); - _ltoa(ci.dVal, buffer, 10); - if (cacheEntry != NULL) - cacheEntry->tszName = mir_a2u(buffer); - return (INT_PTR) buffer; + _ltoa(ci.dVal, retVal, 10); + if (cacheEntry == NULL) + return (INT_PTR)mir_strdup(retVal); + + cacheEntry->tszName = mir_a2u(retVal); + return (INT_PTR)retVal; } } CallContactService(hContact, PSS_GETINFO, SGIF_MINIMAL, 0); - buffer = Translate("(Unknown Contact)"); - return (INT_PTR) buffer; + char* result = Translate("(Unknown Contact)"); + return (INT_PTR)((cacheEntry == NULL) ? mir_strdup(result) : result); } INT_PTR InvalidateDisplayName(WPARAM wParam, LPARAM) -- cgit v1.2.3