don't interpret the first DWORD of data as its size if there is nothing following it (this fixes bug 1791459 for the 2.8 branch)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@48663 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-09-13 18:42:19 +00:00
parent fcf879e4f7
commit e79310d60f

View File

@@ -685,13 +685,14 @@ size_t wxDataObject::GetBufferOffset(const wxDataFormat& format )
return NeedsVerbatimData(format) ? 0 : sizeof(size_t);
}
const void* wxDataObject::GetSizeFromBuffer( const void* buffer, size_t* size,
const wxDataFormat& format )
const void *wxDataObject::GetSizeFromBuffer(const void *buffer,
size_t *size,
const wxDataFormat& format)
{
// hack: the third parameter is declared non-const in Wine's headers so
// cast away the const
size_t realsz = ::HeapSize(::GetProcessHeap(), 0,
wx_const_cast(void*, buffer));
const size_t realsz = ::HeapSize(::GetProcessHeap(), 0,
wx_const_cast(void*, buffer));
if ( realsz == (size_t)-1 )
{
// note that HeapSize() does not set last error
@@ -702,9 +703,13 @@ const void* wxDataObject::GetSizeFromBuffer( const void* buffer, size_t* size,
*size = realsz;
// check if this data has its size prepended (as it was by default for wx
// programs prior 2.6.3):
size_t *p = (size_t *)buffer;
if ( *p == realsz )
// programs prior 2.6.3): notice that we may still mistakenly interpret the
// start of the real data as size (e.g. suppose the object contains 2 ints
// and the first of them is 8...) but there is no way around it as long as
// we want to keep this compatibility hack (it won't be there any more in
// the next major wx version)
DWORD *p = (DWORD *)buffer;
if ( *p == realsz && realsz > sizeof(DWORD) )
{
if ( NeedsVerbatimData(format) )
wxLogDebug(wxT("Apparent data format mismatch: size not needed"));