From cd67a80a9aaecc8646d42863305d5fcee76fe51e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2009 17:25:28 +0000 Subject: [PATCH] Fix off by one errors in wxURLDataObject. wxTextDataObject::SetData() adds the terminating NUL automatically so there is no need to add it to the length when calling it from wxURLDataObject::SetURL(). This change is necessary to fix the unit test in the upcoming fix for #11102. See #11102. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61787 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/ole/dataobj.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/msw/ole/dataobj.cpp b/src/msw/ole/dataobj.cpp index fde08cbcd0..bd369ee4e1 100644 --- a/src/msw/ole/dataobj.cpp +++ b/src/msw/ole/dataobj.cpp @@ -1248,16 +1248,22 @@ void wxURLDataObject::SetURL(const wxString& url) wxCharBuffer urlMB(url.mb_str()); if ( urlMB ) { - const size_t len = strlen(urlMB) + 1; // size with trailing NUL + const size_t len = strlen(urlMB); + #if !wxUSE_UNICODE + // wxTextDataObject takes the number of characters in the string, not + // the size of the buffer (which would be len+1) SetData(wxDF_TEXT, len, urlMB); -#endif - SetData(wxDataFormat(CFSTR_SHELLURL), len, urlMB); +#endif // !wxUSE_UNICODE + + // however CFSTR_SHELLURLDataObject doesn't append NUL automatically + // but we probably still want to have it on the clipboard (just to be + // safe), so do append it + SetData(wxDataFormat(CFSTR_SHELLURL), len + 1, urlMB); } #if wxUSE_UNICODE - // notice that SetData() takes size in bytes - SetData(wxDF_UNICODETEXT, (url.length() + 1)*sizeof(wxChar), url.wc_str()); + SetData(wxDF_UNICODETEXT, url.length()*sizeof(wxChar), url.wc_str()); #endif } -- 2.47.2