From c2bd4ebd4cd99808e7d976a395d90be663f341f0 Mon Sep 17 00:00:00 2001 From: crs Date: Tue, 8 Apr 2003 19:26:35 +0000 Subject: [PATCH] Changed MS clipboard text converters to truncate the clipboard data at the first NUL. This fixes a bug when interoperating with some win32 programs. --- lib/platform/CMSWindowsClipboardTextConverter.cpp | 9 +++++---- lib/platform/CMSWindowsClipboardUTF16Converter.cpp | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/platform/CMSWindowsClipboardTextConverter.cpp b/lib/platform/CMSWindowsClipboardTextConverter.cpp index 7b11cdce..a735094a 100644 --- a/lib/platform/CMSWindowsClipboardTextConverter.cpp +++ b/lib/platform/CMSWindowsClipboardTextConverter.cpp @@ -45,10 +45,11 @@ CMSWindowsClipboardTextConverter::doFromIClipboard(const CString& data) const CString CMSWindowsClipboardTextConverter::doToIClipboard(const CString& data) const { - // convert and strip nul terminator - CString dst = CUnicode::textToUTF8(data); - if (dst.size() > 0 && dst[dst.size() - 1] == '\0') { - dst.erase(dst.size() - 1); + // convert and truncate at first nul terminator + CString dst = CUnicode::textToUTF8(data); + CString::size_type n = dst.find('\0'); + if (n != CString::npos) { + dst.erase(n); } return dst; } diff --git a/lib/platform/CMSWindowsClipboardUTF16Converter.cpp b/lib/platform/CMSWindowsClipboardUTF16Converter.cpp index d0ec7ea3..81b85c60 100644 --- a/lib/platform/CMSWindowsClipboardUTF16Converter.cpp +++ b/lib/platform/CMSWindowsClipboardUTF16Converter.cpp @@ -46,9 +46,10 @@ CString CMSWindowsClipboardUTF16Converter::doToIClipboard(const CString& data) const { // convert and strip nul terminator - CString dst = CUnicode::UTF16ToUTF8(data); - if (dst.size() > 0 && dst[dst.size() - 1] == '\0') { - dst.erase(dst.size() - 1); + CString dst = CUnicode::UTF16ToUTF8(data); + CString::size_type n = dst.find('\0'); + if (n != CString::npos) { + dst.erase(n); } return dst; }