diff options
author | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-07 03:28:32 +0000 |
---|---|---|
committer | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-07 03:28:32 +0000 |
commit | eace8a521b9b47376915569e5708222d6e694acd (patch) | |
tree | 55694a7f94a4d33770b48ba5e2f36f9d1da4d3cc /chrome | |
parent | 15af80eb0cb603cf5a365cb86061bad95f063d40 (diff) | |
download | chromium_src-eace8a521b9b47376915569e5708222d6e694acd.zip chromium_src-eace8a521b9b47376915569e5708222d6e694acd.tar.gz chromium_src-eace8a521b9b47376915569e5708222d6e694acd.tar.bz2 |
Make the OSExchangeDataTest.Html test pass now that I fixed NULL handling in UTF8->wide conversions. CF_HTML format does not need to be NULL terminated.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@480 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/common/os_exchange_data.cc | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/chrome/common/os_exchange_data.cc b/chrome/common/os_exchange_data.cc index 7e311f6..7e4163f 100644 --- a/chrome/common/os_exchange_data.cc +++ b/chrome/common/os_exchange_data.cc @@ -45,7 +45,9 @@ #include "generated_resources.h" // Creates a new STGMEDIUM object to hold the specified text. The caller -// owns the resulting object. +// owns the resulting object. The "Bytes" version does not NULL terminate, the +// string version does. +static STGMEDIUM* GetStorageForBytes(const char* data, size_t bytes); static STGMEDIUM* GetStorageForWString(const std::wstring& data); static STGMEDIUM* GetStorageForString(const std::string& data); // Creates the contents of an Internet Shortcut file for the given URL. @@ -359,7 +361,8 @@ void OSExchangeData::SetFileContents(const std::wstring& filename, } void OSExchangeData::SetCFHtml(const std::wstring& cf_html) { - STGMEDIUM* storage = GetStorageForString(WideToUTF8(cf_html)); + std::string utf8 = WideToUTF8(cf_html); + STGMEDIUM* storage = GetStorageForBytes(utf8.c_str(), utf8.size()); contents_.push_back(new StoredDataInfo( ClipboardUtil::GetHtmlFormat()->cfFormat, storage)); } @@ -620,6 +623,19 @@ ULONG OSExchangeData::Release() { /////////////////////////////////////////////////////////////////////////////// // OSExchangeData, private: +static STGMEDIUM* GetStorageForBytes(const char* data, size_t bytes) { + HANDLE handle = GlobalAlloc(GPTR, static_cast<int>(bytes)); + ScopedHGlobal<char> scoped(handle); + size_t allocated = static_cast<size_t>(GlobalSize(handle)); + memcpy(scoped.get(), data, allocated); + + STGMEDIUM* storage = new STGMEDIUM; + storage->hGlobal = handle; + storage->tymed = TYMED_HGLOBAL; + storage->pUnkForRelease = NULL; + return storage; +} + template<class T> static HGLOBAL CopyStringToGlobalHandle(const T& payload) { int bytes = static_cast<int>(payload.size() + 1) * sizeof(T::value_type); |