From f4ecdaa51d0116a39a6fa8cd1eea257a9d2fd9aa Mon Sep 17 00:00:00 2001 From: "pinkerton%netscape.com" Date: Fri, 13 Aug 1999 21:05:49 +0000 Subject: [PATCH] correctly check result codes of OS calls and null terminate the exported mappings for placing on the clipboard. Fixes bug #11569 (appr chofmann). git-svn-id: svn://10.0.0.236/trunk@43301 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/widget/src/mac/nsClipboard.cpp | 10 ++++++---- mozilla/widget/src/mac/nsMimeMapper.cpp | 7 +++++-- mozilla/widget/src/mac/nsMimeMapper.h | 3 ++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/mozilla/widget/src/mac/nsClipboard.cpp b/mozilla/widget/src/mac/nsClipboard.cpp index 0c96e336bcf..61df99bd28c 100644 --- a/mozilla/widget/src/mac/nsClipboard.cpp +++ b/mozilla/widget/src/mac/nsClipboard.cpp @@ -148,7 +148,8 @@ nsClipboard :: SetNativeClipboardData() } // foreach flavor in transferable delete flavorList; - // write out the mapping data in a special flavor on the clipboard + // write out the mapping data in a special flavor on the clipboard. |mappingLen| + // includes the NULL terminator. short mappingLen = 0; const char* mapping = theMapper.ExportMapping(&mappingLen); long numBytes = ::PutScrap ( mappingLen, nsMimeMapperMac::MappingFlavor(), mapping ); @@ -188,7 +189,7 @@ nsClipboard :: GetNativeClipboardData(nsITransferable * aTransferable) GetDataOffClipboard ( nsMimeMapperMac::MappingFlavor(), &mimeMapperData, nsnull ); nsMimeMapperMac theMapper ( mimeMapperData ); delete [] mimeMapperData; - + // // Now walk down the list of flavors. When we find one that is actually on the // clipboard, copy out the data into the transferable in that format. SetTransferData() @@ -232,8 +233,9 @@ nsClipboard :: GetDataOffClipboard ( ResType inMacFlavor, char** outData, long* return NS_ERROR_FAILURE; // check if it is on the clipboard - long offsetUnused; - if ( ::GetScrap(NULL, inMacFlavor, &offsetUnused) > 0 ) { + long offsetUnused = 0; + OSErr clipResult = ::GetScrap(NULL, inMacFlavor, &offsetUnused); + if ( clipResult > 0 ) { // we have it, get it off the clipboard. Put it into memory that we allocate // with new[] so that the tranferable can own it (and then later use delete[] // on it). diff --git a/mozilla/widget/src/mac/nsMimeMapper.cpp b/mozilla/widget/src/mac/nsMimeMapper.cpp index d3a3eb82126..d644dcade37 100644 --- a/mozilla/widget/src/mac/nsMimeMapper.cpp +++ b/mozilla/widget/src/mac/nsMimeMapper.cpp @@ -152,6 +152,8 @@ nsMimeMapperMac :: ParseMappings ( const char* inMappings ) mMappings.push_back( MimePair(flavor, mimeType) ); currPosition += 10 + 2 + strlen(mimeType); // see ExportMapping() for explanation of this calculation + + ++mCounter; } // while we're not at the end yet } // ParseMappings @@ -163,7 +165,8 @@ nsMimeMapperMac :: ParseMappings ( const char* inMappings ) // The mappings are of the form // <# of pairs> 1..N of (<4 char code> ) // -// Caller is responsible for disposing of the memory allocated here +// Caller is responsible for disposing of the memory allocated here. |outLength| counts +// the null at the end of the string. // char* nsMimeMapperMac :: ExportMapping ( short * outLength ) const @@ -219,7 +222,7 @@ nsMimeMapperMac :: ExportMapping ( short * outLength ) const } // if we got the memory } // if there is anything in our list - *outLength = len; + *outLength = len + 1; // don't forget the NULL return exportBuffer; } // ExportMapping diff --git a/mozilla/widget/src/mac/nsMimeMapper.h b/mozilla/widget/src/mac/nsMimeMapper.h index 06c2315df5d..0b3028df1ac 100644 --- a/mozilla/widget/src/mac/nsMimeMapper.h +++ b/mozilla/widget/src/mac/nsMimeMapper.h @@ -64,7 +64,8 @@ public: void MapMacOSTypeToMimeType ( ResType inMacType, nsString & outMimeStr ) ; // Takes the internal mappings and converts them to a string for - // placing on the clipboard or in a drag item. + // placing on the clipboard or in a drag item. |outLength| includes + // the NULL at the end of the string. char* ExportMapping ( short * outLength ) const; static ResType MappingFlavor ( ) { return kMappingFlavor; }