summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/views/shell_dialogs.cc8
-rw-r--r--chrome/common/win_util.cc7
2 files changed, 3 insertions, 12 deletions
diff --git a/chrome/browser/views/shell_dialogs.cc b/chrome/browser/views/shell_dialogs.cc
index 483e223..7e41937 100644
--- a/chrome/browser/views/shell_dialogs.cc
+++ b/chrome/browser/views/shell_dialogs.cc
@@ -13,6 +13,7 @@
#include "base/file_util.h"
#include "base/registry.h"
+#include "base/string_util.h"
#include "base/thread.h"
#include "chrome/browser/browser_process.h"
#include "chrome/common/gfx/chrome_font.h"
@@ -340,13 +341,8 @@ bool SelectFileDialogImpl::RunOpenFileDialog(const std::wstring& title,
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = owner;
- // This will clamp the number of characters copied from the supplied path
- // to the value of MAX_PATH.
- size_t name_size = std::min(path->length() + 1,
- static_cast<size_t>(MAX_PATH));
wchar_t filename[MAX_PATH];
- memcpy(filename, path->c_str(), name_size * sizeof(wchar_t));
- filename[MAX_PATH - 1] = '\0';
+ base::wcslcpy(filename, path->c_str(), arraysize(filename));
ofn.lpstrFile = filename;
ofn.nMaxFile = MAX_PATH;
diff --git a/chrome/common/win_util.cc b/chrome/common/win_util.cc
index 36e1f86..8bc7651 100644
--- a/chrome/common/win_util.cc
+++ b/chrome/common/win_util.cc
@@ -397,13 +397,8 @@ bool SaveFileAsWithFilter(HWND owner,
// will be written into by Windows when the user is done with the dialog box.
std::wstring file_part = file_util::GetFilenameFromPath(suggested_name);
- // This will clamp the number of characters copied from the supplied path
- // to the value of MAX_PATH.
- size_t name_size = std::min(file_part.length() + 1,
- static_cast<size_t>(MAX_PATH));
wchar_t file_name[MAX_PATH];
- memcpy(file_name, file_part.c_str(), name_size * sizeof(wchar_t));
- file_name[MAX_PATH - 1] = '\0';
+ base::wcslcpy(file_name, file_part.c_str(), arraysize(file_name));
OPENFILENAME save_as;
// We must do this otherwise the ofn's FlagsEx may be initialized to random