Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: sandbox/src/sandbox_utils.cc

Issue 8418034: Make string_util::WriteInto() DCHECK() that the supplied |length_with_null| > 1, meaning that the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sandbox/src/sandbox_utils.h" 5 #include "sandbox/src/sandbox_utils.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/win/windows_version.h" 10 #include "base/win/windows_version.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 if (!RtlInitUnicodeString) { 69 if (!RtlInitUnicodeString) {
70 HMODULE ntdll = ::GetModuleHandle(kNtdllName); 70 HMODULE ntdll = ::GetModuleHandle(kNtdllName);
71 RtlInitUnicodeString = reinterpret_cast<RtlInitUnicodeStringFunction>( 71 RtlInitUnicodeString = reinterpret_cast<RtlInitUnicodeStringFunction>(
72 GetProcAddress(ntdll, "RtlInitUnicodeString")); 72 GetProcAddress(ntdll, "RtlInitUnicodeString"));
73 DCHECK(RtlInitUnicodeString); 73 DCHECK(RtlInitUnicodeString);
74 } 74 }
75 RtlInitUnicodeString(uni_name, name.c_str()); 75 RtlInitUnicodeString(uni_name, name.c_str());
76 InitializeObjectAttributes(obj_attr, uni_name, attributes, root, NULL); 76 InitializeObjectAttributes(obj_attr, uni_name, attributes, root, NULL);
77 } 77 }
78 78
79 std::string WideToMultiByte(const std::wstring& wide) {
80 if (wide.length() == 0)
81 return std::string();
82
83 // compute the length of the buffer we'll need
84 int charcount = WideCharToMultiByte(CP_UTF8, 0, wide.c_str(), -1,
85 NULL, 0, NULL, NULL);
86 if (charcount == 0)
87 return std::string();
88
89 std::string mb;
90 WideCharToMultiByte(CP_UTF8, 0, wide.c_str(), -1,
91 WriteInto(&mb, charcount), charcount, NULL, NULL);
92
93 return mb;
94 }
95
96 }; // namespace sandbox 79 }; // namespace sandbox
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698