From 0137f837ddf36dfd6e7de6decdc763a62b4fdb2c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 19 Jun 2016 14:38:21 +0000 Subject: fix for a memory corruption git-svn-id: http://svn.miranda-ng.org/main/trunk@17011 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/MSN/src/msn_misc.cpp | 21 +++++++-------------- protocols/MSN/src/version.h | 2 +- 2 files changed, 8 insertions(+), 15 deletions(-) (limited to 'protocols/MSN') diff --git a/protocols/MSN/src/msn_misc.cpp b/protocols/MSN/src/msn_misc.cpp index 3ac46a9223..d60db4f4c4 100644 --- a/protocols/MSN/src/msn_misc.cpp +++ b/protocols/MSN/src/msn_misc.cpp @@ -685,35 +685,28 @@ int ThreadData::sendPacket(const char* cmd, const char* fmt, ...) { if (this == NULL) return 0; - size_t strsize = 512; - char* str = (char*)mir_alloc(strsize); - + CMStringA str; int thisTrid = 0; if (fmt == NULL) - strncpy_s(str, strsize, cmd, _TRUNCATE); + str = cmd; else { thisTrid = InterlockedIncrement(&mTrid); if (fmt[0] == '\0') - mir_snprintf(str, strsize, "%s %d", cmd, thisTrid); + str.AppendFormat("%s %d", cmd, thisTrid); else { va_list vararg; va_start(vararg, fmt); - - int paramStart = mir_snprintf(str, strsize, "%s %d ", cmd, thisTrid); - while (mir_vsnprintf(str + paramStart, strsize - paramStart - 3, fmt, vararg) == -1) - str = (char*)mir_realloc(str, strsize += 512); - - str[strsize - 3] = 0; + str.AppendFormat("%s %d ", cmd, thisTrid); + str.AppendFormatV(fmt, vararg); va_end(vararg); } } if (strchr(str, '\r') == NULL) - mir_strcat(str, "\r\n"); + str += "\r\n"; - int result = send(str, mir_strlen(str)); - mir_free(str); + int result = send(str, str.GetLength()); return (result > 0) ? thisTrid : -1; } diff --git a/protocols/MSN/src/version.h b/protocols/MSN/src/version.h index b8501d6681..904c641c88 100644 --- a/protocols/MSN/src/version.h +++ b/protocols/MSN/src/version.h @@ -21,7 +21,7 @@ along with this program. If not, see . #define __MAJOR_VERSION 0 #define __MINOR_VERSION 12 #define __RELEASE_NUM 1 -#define __BUILD_NUM 1 +#define __BUILD_NUM 2 #include -- cgit v1.2.3