From db3809c5db0a3a1bf82ecd59a5523e8831c207dd Mon Sep 17 00:00:00 2001
From: George Hazan <george.hazan@gmail.com>
Date: Fri, 20 Sep 2013 18:16:08 +0000
Subject: memory corruption fix (for 64-bit targets only)

git-svn-id: http://svn.miranda-ng.org/main/trunk@6140 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
---
 plugins/Variables/src/parse_miranda.cpp | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

(limited to 'plugins/Variables')

diff --git a/plugins/Variables/src/parse_miranda.cpp b/plugins/Variables/src/parse_miranda.cpp
index 2e687a1fbf..de196803bc 100644
--- a/plugins/Variables/src/parse_miranda.cpp
+++ b/plugins/Variables/src/parse_miranda.cpp
@@ -473,33 +473,28 @@ static TCHAR *parseSpecialContact(ARGUMENTSINFO *ai)
 		return NULL;
 
 	ai->flags |= AIF_DONTPARSE;
-	TCHAR *szUniqueID = NULL;
+	ptrT szUniqueID;
 	char *szProto = GetContactProto(ai->fi->hContact);
 	if (szProto != NULL)
 		szUniqueID = getContactInfoT(CNF_UNIQUEID, ai->fi->hContact);
 
 	if (szUniqueID == NULL) {
 		szProto = PROTOID_HANDLE;
-		szUniqueID = (TCHAR*)mir_alloc(32);
-		mir_sntprintf(szUniqueID, 32, _T("%p"), ai->fi->hContact);
-		if (szProto == NULL || szUniqueID == NULL)
+		szUniqueID = (TCHAR*)mir_alloc(40);
+		if (szUniqueID == NULL)
 			return NULL;
+		mir_sntprintf(szUniqueID, 20, _T("%p"), ai->fi->hContact);
 	}
 
+	if (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);
+	if (res == NULL)
 		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);
-	}
 
+	mir_sntprintf(res, size, _T("<%S:%s>"), szProto, szUniqueID);
 	return res;
 }
 
-- 
cgit v1.2.3