diff options
author | George Hazan <george.hazan@gmail.com> | 2016-06-12 21:38:05 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2016-06-12 21:38:05 +0000 |
commit | 3dbe055401e7ccaaff2ea6b362bc4bcaac6ca98a (patch) | |
tree | 253e791915edd40d1f0aaae57b879805b0fb5797 /src/mir_app | |
parent | a1d008f3a624cdf121ef8d5e6eb275b6bec65223 (diff) |
more foolproof variant of NetlibBinBuffer
git-svn-id: http://svn.miranda-ng.org/main/trunk@16960 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/mir_app')
-rw-r--r-- | src/mir_app/src/netlib.h | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/mir_app/src/netlib.h b/src/mir_app/src/netlib.h index bacad422df..f653de6f8f 100644 --- a/src/mir_app/src/netlib.h +++ b/src/mir_app/src/netlib.h @@ -87,6 +87,9 @@ public: void append(void *pBuf, int bufLen)
{
+ if (pBuf == NULL || bufLen == 0)
+ return;
+
m_buf = (char*)mir_realloc(m_buf, bufLen + m_len);
if (m_buf) {
memcpy(m_buf + m_len, pBuf, bufLen);
@@ -97,6 +100,9 @@ public: void appendBefore(void *pBuf, int bufLen)
{
+ if (pBuf == NULL || bufLen == 0)
+ return;
+
m_buf = (char*)mir_realloc(m_buf, bufLen + m_len);
if (m_buf) {
memmove(m_buf + bufLen, m_buf, m_len);
@@ -108,8 +114,17 @@ public: void remove(int sz)
{
- memmove(m_buf, m_buf + sz, m_len - sz);
- m_len -= sz;
+ if (sz > m_len)
+ m_len = sz;
+
+ if (m_len == sz) {
+ m_len = 0;
+ mir_free(m_buf); m_buf = NULL;
+ }
+ else {
+ memmove(m_buf, m_buf + sz, m_len - sz);
+ m_len -= sz;
+ }
}
};
|