From 7244abb3e9c0a4cbfbf688643b7016a0ff0e24b1 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 29 Mar 2015 16:30:53 +0000 Subject: painful death of manual pointer manipulations git-svn-id: http://svn.miranda-ng.org/main/trunk@12542 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Variables/src/parse_metacontacts.cpp | 59 ++++++---------------------- 1 file changed, 12 insertions(+), 47 deletions(-) (limited to 'plugins/Variables') diff --git a/plugins/Variables/src/parse_metacontacts.cpp b/plugins/Variables/src/parse_metacontacts.cpp index 281cac0556..131b24518f 100644 --- a/plugins/Variables/src/parse_metacontacts.cpp +++ b/plugins/Variables/src/parse_metacontacts.cpp @@ -55,10 +55,7 @@ static TCHAR *parseGetParent(ARGUMENTSINFO *ai) szUniqueID = mir_tstrdup(tszID); } - if (szUniqueID == NULL) - return NULL; - - return mir_tstrdup(CMString(FORMAT, _T("<%S:%s>"), szProto, szUniqueID)); + return CMString(FORMAT, _T("<%S:%s>"), szProto, szUniqueID).Detouch(); } static TCHAR *parseGetDefault(ARGUMENTSINFO *ai) @@ -86,34 +83,19 @@ static TCHAR *parseGetDefault(ARGUMENTSINFO *ai) if (hContact == NULL) return NULL; - TCHAR* szUniqueID = NULL; + ptrT szUniqueID; char* szProto = GetContactProto(hContact); if (szProto != NULL) szUniqueID = getContactInfoT(CNF_UNIQUEID, hContact); if (szUniqueID == NULL) { szProto = PROTOID_HANDLE; - szUniqueID = (TCHAR *)mir_alloc(32); - mir_sntprintf(szUniqueID, 32, _T("%p"), hContact); - if (szProto == NULL || szUniqueID == NULL) - return NULL; - } - - size_t size = strlen(szProto) + _tcslen(szUniqueID) + 4; - TCHAR *res = (TCHAR *)mir_alloc(size * sizeof(TCHAR)); - if (res == NULL) { - mir_free(szUniqueID); - return NULL; - } - - TCHAR *tszProto = mir_a2t(szProto); - if (tszProto != NULL && szUniqueID != NULL) { - mir_sntprintf(res, size, _T("<%s:%s>"), tszProto, szUniqueID); - mir_free(szUniqueID); - mir_free(tszProto); + TCHAR tszID[40]; + mir_sntprintf(tszID, SIZEOF(tszID), _T("%p"), hContact); + szUniqueID = mir_tstrdup(tszID); } - return res; + return CMString(FORMAT, _T("<%S:%s>"), szProto, szUniqueID).Detouch(); } static TCHAR *parseGetMostOnline(ARGUMENTSINFO *ai) @@ -141,36 +123,19 @@ static TCHAR *parseGetMostOnline(ARGUMENTSINFO *ai) if (hContact == NULL) return NULL; - TCHAR* szUniqueID = NULL; - char* szProto = GetContactProto(hContact); + ptrT szUniqueID; + char *szProto = GetContactProto(hContact); if (szProto != NULL) szUniqueID = getContactInfoT(CNF_UNIQUEID, hContact); if (szUniqueID == NULL) { szProto = PROTOID_HANDLE; - if (szProto == NULL) - return NULL; - szUniqueID = (TCHAR *)mir_alloc(32); - if (szUniqueID == NULL) - return NULL; - mir_sntprintf(szUniqueID, 32, _T("%p"), hContact); - } - - size_t size = strlen(szProto) + _tcslen(szUniqueID) + 4; - TCHAR *res = (TCHAR *)mir_alloc(size * sizeof(TCHAR)); - if (res == NULL) { - mir_free(szUniqueID); - return NULL; - } - - TCHAR *tszProto = mir_a2t(szProto); - if (tszProto != NULL && szUniqueID != NULL) { - mir_sntprintf(res, size, _T("<%s:%s>"), tszProto, szUniqueID); - mir_free(szUniqueID); - mir_free(tszProto); + TCHAR tszID[40]; + mir_sntprintf(tszID, SIZEOF(tszID), _T("%p"), hContact); + szUniqueID = mir_tstrdup(tszID); } - return res; + return CMString(FORMAT, _T("<%S:%s>"), szProto, szUniqueID).Detouch(); } void registerMetaContactsTokens() -- cgit v1.2.3