aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <unknown>2010-03-11 10:05:45 +0000
committernyamatongwe <unknown>2010-03-11 10:05:45 +0000
commit3433f48291b3b16e5393a291c2bc3a34d35e8d4c (patch)
treed6957a784092bdcdada5b336bece11334678a963
parent1ce4dc2d8079ddde0946942435f7872fbdb2e717 (diff)
downloadscintilla-mirror-3433f48291b3b16e5393a291c2bc3a34d35e8d4c.tar.gz
Use allocated sizes rather than relying on 0 termination.
-rw-r--r--win32/ScintillaWin.cxx9
1 files changed, 5 insertions, 4 deletions
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index e3dc8b474..9edd56ad3 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -1414,10 +1414,10 @@ void ScintillaWin::Paste() {
// Convert from Unicode to current Scintilla code page
UINT cpDest = CodePageFromCharSet(
vs.styles[STYLE_DEFAULT].characterSet, pdoc->dbcsCodePage);
- len = ::WideCharToMultiByte(cpDest, 0, uptr, -1,
+ len = ::WideCharToMultiByte(cpDest, 0, uptr, memUSelection.Size() / 2,
NULL, 0, NULL, NULL) - 1; // subtract 0 terminator
putf = new char[len + 1];
- ::WideCharToMultiByte(cpDest, 0, uptr, -1,
+ ::WideCharToMultiByte(cpDest, 0, uptr, memUSelection.Size() / 2,
putf, len + 1, NULL, NULL);
}
@@ -1942,10 +1942,11 @@ void ScintillaWin::CopyToClipboard(const SelectionText &selectedText) {
// Convert to Unicode using the current Scintilla code page
UINT cpSrc = CodePageFromCharSet(
selectedText.characterSet, selectedText.codePage);
- uniText.Allocate(2 * selectedText.len);
+ int uLen = ::MultiByteToWideChar(cpSrc, 0, selectedText.s, selectedText.len, 0, 0);
+ uniText.Allocate(2 * uLen);
if (uniText) {
::MultiByteToWideChar(cpSrc, 0, selectedText.s, selectedText.len,
- static_cast<wchar_t *>(uniText.ptr), selectedText.len);
+ static_cast<wchar_t *>(uniText.ptr), uLen);
}
}