From aadfaada7a41513ea6ab8ad00c34f597f3ff9c6e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 22 Aug 2020 19:24:11 +0200 Subject: [PATCH] Fix crash when using custom DnD formats under Wine Using ::HeapSize() on a global pointer is wrong, and even though it somehow still works under "genuine" MSW, it crashes under Wine. Fix this by using ::GlobalSize() instead, which is the right function to use with this kind of pointer. Thanks to Damjan Jovanovic for the analysis of the problem in Wine bugzilla (see https://bugs.winehq.org/show_bug.cgi?id=38924#c10). Closes #18887. --- src/msw/ole/dataobj.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/msw/ole/dataobj.cpp b/src/msw/ole/dataobj.cpp index e584ced903..9d3a89c16b 100644 --- a/src/msw/ole/dataobj.cpp +++ b/src/msw/ole/dataobj.cpp @@ -975,14 +975,10 @@ const void *wxDataObject::GetSizeFromBuffer(const void *buffer, size_t *size, const wxDataFormat& WXUNUSED(format)) { - // hack: the third parameter is declared non-const in Wine's headers so - // cast away the const - const size_t realsz = ::HeapSize(::GetProcessHeap(), 0, - const_cast(buffer)); - if ( realsz == (size_t)-1 ) + const size_t realsz = ::GlobalSize(::GlobalHandle(buffer)); + if ( !realsz ) { - // note that HeapSize() does not set last error - wxLogApiError(wxT("HeapSize"), 0); + wxLogLastError(wxT("GlobalSize")); return NULL; }