summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authoryosin@chromium.org <yosin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-09 08:57:26 +0000
committeryosin@chromium.org <yosin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-09 08:57:26 +0000
commit32f5aebd454d2bad69a231fbd4a8152ca4796dbf (patch)
tree7e8813e33bfe9228e32c8d10206df1d83e5a173e /ui
parent5a13067f76fc58efe50dacbb232782ccb541bc5d (diff)
downloadchromium_src-32f5aebd454d2bad69a231fbd4a8152ca4796dbf.zip
chromium_src-32f5aebd454d2bad69a231fbd4a8152ca4796dbf.tar.gz
chromium_src-32f5aebd454d2bad69a231fbd4a8152ca4796dbf.tar.bz2
* Truncate file name longer than MAX_PATH(260).
* Change for cpplint.py BUG=93601 TEST=Manual on Windows Review URL: http://codereview.chromium.org/7778008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100373 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/base/dragdrop/os_exchange_data_provider_win.cc31
1 files changed, 16 insertions, 15 deletions
diff --git a/ui/base/dragdrop/os_exchange_data_provider_win.cc b/ui/base/dragdrop/os_exchange_data_provider_win.cc
index 3ecbefa..ad6d308 100644
--- a/ui/base/dragdrop/os_exchange_data_provider_win.cc
+++ b/ui/base/dragdrop/os_exchange_data_provider_win.cc
@@ -4,6 +4,9 @@
#include "ui/base/dragdrop/os_exchange_data_provider_win.h"
+#include <algorithm>
+#include <vector>
+
#include "base/file_path.h"
#include "base/i18n/file_util_icu.h"
#include "base/logging.h"
@@ -124,7 +127,7 @@ STDMETHODIMP FormatEtcEnumerator::Next(
ULONG count, FORMATETC* elements_array, ULONG* elements_fetched) {
// MSDN says |elements_fetched| is allowed to be NULL if count is 1.
if (!elements_fetched)
- DCHECK(count == 1);
+ DCHECK_EQ(count, 1ul);
// This method copies count elements into |elements_array|.
ULONG index = 0;
@@ -403,7 +406,7 @@ bool OSExchangeDataProviderWin::GetPickledData(CLIPFORMAT format,
if (SUCCEEDED(source_object_->GetData(&format_etc, &medium))) {
if (medium.tymed & TYMED_HGLOBAL) {
base::win::ScopedHGlobal<char> c_data(medium.hGlobal);
- DCHECK(c_data.Size() > 0);
+ DCHECK_GT(c_data.Size(), 0u);
// Need to subtract 1 as SetPickledData adds an extra byte to the end.
*data = Pickle(c_data.get(), static_cast<int>(c_data.Size() - 1));
success = true;
@@ -903,35 +906,33 @@ static STGMEDIUM* GetStorageForFileName(const FilePath& path) {
STGMEDIUM* storage = new STGMEDIUM;
storage->tymed = TYMED_HGLOBAL;
- storage->hGlobal = drop_files;
+ storage->hGlobal = hdata;
storage->pUnkForRelease = NULL;
return storage;
}
static STGMEDIUM* GetStorageForFileDescriptor(
const FilePath& path) {
- string16 valid_file_name = path.value();
- DCHECK(!valid_file_name.empty() && valid_file_name.size() + 1 <= MAX_PATH);
- HANDLE handle = GlobalAlloc(GPTR, sizeof(FILEGROUPDESCRIPTOR));
- FILEGROUPDESCRIPTOR* descriptor =
- reinterpret_cast<FILEGROUPDESCRIPTOR*>(GlobalLock(handle));
+ string16 file_name = path.value();
+ DCHECK(!file_name.empty());
+ HANDLE hdata = GlobalAlloc(GPTR, sizeof(FILEGROUPDESCRIPTOR));
+ base::win::ScopedHGlobal<FILEGROUPDESCRIPTOR> locked_mem(hdata);
+ FILEGROUPDESCRIPTOR* descriptor = locked_mem.get();
descriptor->cItems = 1;
- wcscpy_s(descriptor->fgd[0].cFileName,
- valid_file_name.size() + 1,
- valid_file_name.c_str());
descriptor->fgd[0].dwFlags = FD_LINKUI;
-
- GlobalUnlock(handle);
+ wcsncpy_s(descriptor->fgd[0].cFileName,
+ MAX_PATH,
+ file_name.c_str(),
+ std::min(file_name.size(), MAX_PATH - 1u));
STGMEDIUM* storage = new STGMEDIUM;
- storage->hGlobal = handle;
storage->tymed = TYMED_HGLOBAL;
+ storage->hGlobal = hdata;
storage->pUnkForRelease = NULL;
return storage;
}
-
///////////////////////////////////////////////////////////////////////////////
// OSExchangeData, public: