From a5ddc3e7b3231e97cc8d1e5b867f4129eea1ddfb Mon Sep 17 00:00:00 2001 From: Yuval Date: Mon, 4 May 2009 15:07:54 +0000 Subject: [PATCH] [BUGFIX] Added protection against invalid start/end markers in wchar2char and char2wchar. This is needed for find in files where the result is found in a line containing the null character (binary files). This caused an Access violation exception because the markers were past the EOL in this case (char2wchar), and then they were used in wchar2char. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@475 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/MISC/Common/Common.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/PowerEditor/src/MISC/Common/Common.cpp b/PowerEditor/src/MISC/Common/Common.cpp index f6d8e7126..52bb6f615 100644 --- a/PowerEditor/src/MISC/Common/Common.cpp +++ b/PowerEditor/src/MISC/Common/Common.cpp @@ -286,9 +286,14 @@ const wchar_t * WcharMbcsConvertor::char2wchar(const char * mbcs2Convert, UINT c _wideCharAllocLen = len; _wideCharStr = new wchar_t[_wideCharAllocLen]; } - MultiByteToWideChar(codepage, 0, mbcs2Convert, -1, _wideCharStr, len); + len = MultiByteToWideChar(codepage, 0, mbcs2Convert, -1, _wideCharStr, len); *mstart = MultiByteToWideChar(codepage, 0, mbcs2Convert, *mstart, _wideCharStr, 0); *mend = MultiByteToWideChar(codepage, 0, mbcs2Convert, *mend, _wideCharStr, 0); + if (*mstart >= len || *mend >= len) + { + *mstart = 0; + *mend = 0; + } } else { @@ -341,9 +346,14 @@ const char * WcharMbcsConvertor::wchar2char(const wchar_t * wcharStr2Convert, UI _multiByteAllocLen = len; _multiByteStr = new char[_multiByteAllocLen]; } - WideCharToMultiByte(codepage, 0, wcharStr2Convert, -1, _multiByteStr, len, NULL, NULL); + len = WideCharToMultiByte(codepage, 0, wcharStr2Convert, -1, _multiByteStr, len, NULL, NULL); // not needed? *mstart = WideCharToMultiByte(codepage, 0, wcharStr2Convert, *mstart, _multiByteStr, 0, NULL, NULL); *mend = WideCharToMultiByte(codepage, 0, wcharStr2Convert, *mend, _multiByteStr, 0, NULL, NULL); + if (*mstart >= len || *mend >= len) + { + *mstart = 0; + *mend = 0; + } } else _multiByteStr[0] = 0;