From: David Surovell Date: Mon, 6 Feb 2006 16:24:26 +0000 (+0000) Subject: added protection against non-file drop targets receiving files (and subsequently... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/63c6e6c80637791d4a290811108157a51c13f72d added protection against non-file drop targets receiving files (and subsequently crashing) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37351 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/mac/carbon/dnd.cpp b/src/mac/carbon/dnd.cpp index dac1bb95ef..f5212eb4e2 100644 --- a/src/mac/carbon/dnd.cpp +++ b/src/mac/carbon/dnd.cpp @@ -245,26 +245,34 @@ bool wxDropTarget::GetData() theData[dataSize] = 0 ; m_dataObject->SetData( wxDataFormat(wxDF_TEXT), dataSize , theData ); } - #if wxUSE_UNICODE +#if wxUSE_UNICODE else if ( theType == kScrapFlavorTypeUnicode ) { theData[dataSize + 0] = theData[dataSize + 1] = 0 ; m_dataObject->SetData( wxDataFormat(wxDF_UNICODETEXT), dataSize , theData ); } - #endif +#endif else if ( theType == kDragFlavorTypeHFS ) { - HFSFlavor* theFile = (HFSFlavor*) theData ; - wxString name = wxMacFSSpec2MacFilename( &theFile->fileSpec ) ; - if ( !firstFileAdded ) + wxFileDataObject *fdo = dynamic_cast(m_dataObject); + wxASSERT( fdo != NULL ); + + if ((theData != NULL) && (fdo != NULL)) { - // reset file list - ((wxFileDataObject*)m_dataObject)->SetData( 0 , "" ) ; - firstFileAdded = true ; + HFSFlavor* theFile = (HFSFlavor*) theData ; + wxString name = wxMacFSSpec2MacFilename( &theFile->fileSpec ) ; + + if ( !firstFileAdded ) + { + // reset file list + fdo->SetData( 0 , "" ) ; + firstFileAdded = true ; + } + + if (!name.IsEmpty()) + fdo->AddFile( name ) ; } - - ((wxFileDataObject*)m_dataObject)->AddFile( name ) ; } else {