aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Editor.cxx1
-rw-r--r--src/Editor.h2
-rw-r--r--win32/ScintillaWin.cxx12
3 files changed, 6 insertions, 9 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 2331e64e0..ce606ee00 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -5487,7 +5487,6 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
if (selectedText.len) {
for (; iChar < selectedText.len; iChar++)
ptr[iChar] = selectedText.s[iChar];
- ptr[iChar] = '\0';
} else {
ptr[0] = '\0';
}
diff --git a/src/Editor.h b/src/Editor.h
index 6eccb50bd..08c56f7a4 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -126,6 +126,8 @@ public:
};
/**
+ * Hold a piece of text selected for copying or dragging.
+ * The text is expected to hold a terminating '\0'.
*/
class SelectionText {
public:
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index 097b8a84f..7f52560d5 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -1559,11 +1559,10 @@ void ScintillaWin::CopyToClipboard(const SelectionText &selectedText) {
::EmptyClipboard();
HGLOBAL hand = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
- selectedText.len + 1);
+ selectedText.len);
if (hand) {
char *ptr = static_cast<char *>(::GlobalLock(hand));
memcpy(ptr, selectedText.s, selectedText.len);
- ptr[selectedText.len] = '\0';
::GlobalUnlock(hand);
}
::SetClipboardData(CF_TEXT, hand);
@@ -1571,11 +1570,10 @@ void ScintillaWin::CopyToClipboard(const SelectionText &selectedText) {
if (IsUnicodeMode()) {
int uchars = UCS2Length(selectedText.s, selectedText.len);
HGLOBAL uhand = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
- 2 * (uchars + 1));
+ 2 * (uchars));
if (uhand) {
wchar_t *uptr = static_cast<wchar_t *>(::GlobalLock(uhand));
UCS2FromUTF8(selectedText.s, selectedText.len, uptr, uchars);
- uptr[uchars] = 0;
::GlobalUnlock(uhand);
}
::SetClipboardData(CF_UNICODETEXT, uhand);
@@ -1870,20 +1868,18 @@ STDMETHODIMP ScintillaWin::GetData(FORMATETC *pFEIn, STGMEDIUM *pSTM) {
HGLOBAL hand;
if (pFEIn->cfFormat == CF_UNICODETEXT) {
int uchars = UCS2Length(drag.s, drag.len);
- hand = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, 2 * (uchars + 1));
+ hand = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, 2 * (uchars));
if (hand) {
wchar_t *uptr = static_cast<wchar_t *>(::GlobalLock(hand));
UCS2FromUTF8(drag.s, drag.len, uptr, uchars);
- uptr[uchars] = 0;
}
} else {
- hand = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, drag.len + 1);
+ hand = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, drag.len);
if (hand) {
char *ptr = static_cast<char *>(::GlobalLock(hand));
for (int i = 0; i < drag.len; i++) {
ptr[i] = drag.s[i];
}
- ptr[drag.len] = '\0';
}
}
::GlobalUnlock(hand);