From aa36bdbe3da4e710417b19113b9f472b2a9cf99d Mon Sep 17 00:00:00 2001 From: pescuma Date: Wed, 19 Nov 2008 00:05:43 +0000 Subject: Fix for Buffer crash and CHECK_VERSION git-svn-id: http://pescuma.googlecode.com/svn/trunk/Miranda@118 c086bb3d-8645-0410-b8da-73a8550f86e7 --- Plugins/utils/mir_buffer.h | 11 +++++------ Plugins/utils/mir_memory.cpp | 10 +++++++++- Plugins/utils/mir_memory.h | 21 ++++++++++++++++++++- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Plugins/utils/mir_buffer.h b/Plugins/utils/mir_buffer.h index 1bcdab3..4a5f012 100644 --- a/Plugins/utils/mir_buffer.h +++ b/Plugins/utils/mir_buffer.h @@ -157,9 +157,9 @@ class Buffer { size = total + 256 - total % 256; if (str == NULL) - str = (T *) malloc(size * sizeof(T)); + str = (T *) mir_alloc(size * sizeof(T)); else - str = (T *) realloc(str, size * sizeof(T)); + str = (T *) mir_realloc(str, size * sizeof(T)); } } @@ -167,7 +167,7 @@ class Buffer { if (str != NULL) { - ::free(str); + mir_free(str); str = NULL; len = size = 0; } @@ -181,7 +181,7 @@ class Buffer void append(T app) { - alloc(len + 1); + alloc(len + 1 + 1); str[len] = app; len++; @@ -190,7 +190,7 @@ class Buffer void appendn(size_t n, T app) { - alloc(len + n); + alloc(len + n + 1); for(; n > 0; n--) { @@ -346,7 +346,6 @@ class Buffer str[i] = str[len-i-1]; str[len-i-1] = tmp; } - pack(); } T *appender(size_t appLen) diff --git a/Plugins/utils/mir_memory.cpp b/Plugins/utils/mir_memory.cpp index cea960b..615f3dc 100644 --- a/Plugins/utils/mir_memory.cpp +++ b/Plugins/utils/mir_memory.cpp @@ -18,9 +18,9 @@ Boston, MA 02111-1307, USA. */ +#define MIRANDA_VER 0x0700 #include "mir_memory.h" -#define MIRANDA_VER 0x0700 #include #include @@ -35,6 +35,14 @@ void init_mir_malloc() } +BOOL mir_is_unicode() +{ + char ver[1024]; + CallService(MS_SYSTEM_GETVERSIONTEXT, (WPARAM) sizeof(ver), (LPARAM) ver); + return strstr(ver, "Unicode") != NULL; +} + + void * mir_alloc0(size_t size) { void * ptr = mir_alloc(size); diff --git a/Plugins/utils/mir_memory.h b/Plugins/utils/mir_memory.h index ef2a0d4..52440ae 100644 --- a/Plugins/utils/mir_memory.h +++ b/Plugins/utils/mir_memory.h @@ -28,12 +28,23 @@ Boston, MA 02111-1307, USA. void init_mir_malloc(); +BOOL mir_is_unicode(); + + void * mir_alloc0(size_t size); int strcmpnull(char *str1, char *str2); int strcmpnullW(WCHAR *str1, WCHAR *str2); -#ifdef _UNICODE +#ifdef UNICODE + +#define CHECK_VERSION(_NAME_) \ + if (!mir_is_unicode()) \ + { \ + MessageBox(NULL, _T("Your Miranda is ansi. You have to install ansi ") _T(_NAME_), \ + _T(_NAME_), MB_OK | MB_ICONERROR); \ + return -1; \ + } # define lstrcmpnull strcmpnullW @@ -48,6 +59,14 @@ int strcmpnullW(WCHAR *str1, WCHAR *str2); #else +#define CHECK_VERSION(_NAME_) \ + if (mir_is_unicode()) \ + { \ + MessageBox(NULL, _T("Your Miranda is unicode. You have to install unicode ") _T(_NAME_), \ + _T(_NAME_), MB_OK | MB_ICONERROR); \ + return -1; \ + } + # define lstrcmpnull strcmpnull #define INPLACE_CHAR_TO_TCHAR(_new_var_, _size_, _old_var_) \ -- cgit v1.2.3