summaryrefslogtreecommitdiff
path: root/protocols/MSN/src/msn_misc.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2016-06-19 14:38:21 +0000
committerGeorge Hazan <george.hazan@gmail.com>2016-06-19 14:38:21 +0000
commit0137f837ddf36dfd6e7de6decdc763a62b4fdb2c (patch)
treea662e386ece065e08b429350703b6212bc3db351 /protocols/MSN/src/msn_misc.cpp
parent0fb97def52d30f7cb3e7e849420f74427523646b (diff)
fix for a memory corruption
git-svn-id: http://svn.miranda-ng.org/main/trunk@17011 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/MSN/src/msn_misc.cpp')
-rw-r--r--protocols/MSN/src/msn_misc.cpp21
1 files changed, 7 insertions, 14 deletions
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;
}