Skip to content

Commit e178122

Browse files
[lldb] switch to using std::wstring
1 parent 2827308 commit e178122

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

lldb/source/Host/windows/Host.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -325,26 +325,30 @@ class WindowsEventLog {
325325

326326
static llvm::ManagedStatic<WindowsEventLog> event_log;
327327

328-
static LPCWSTR AnsiToUtf16(const std::string &ansi) {
328+
static std::wstring AnsiToUtf16(const std::string &ansi) {
329329
if (ansi.empty())
330-
return nullptr;
330+
return {};
331+
331332
const int unicode_length =
332333
MultiByteToWideChar(CP_ACP, 0, ansi.c_str(), -1, nullptr, 0);
333-
WCHAR *unicode = new WCHAR[unicode_length];
334-
MultiByteToWideChar(CP_ACP, 0, ansi.c_str(), -1, unicode, unicode_length);
334+
if (unicode_length == 0)
335+
return {};
336+
337+
std::wstring unicode(unicode_length, L'\0');
338+
MultiByteToWideChar(CP_ACP, 0, ansi.c_str(), -1, &unicode[0], unicode_length);
335339
return unicode;
336340
}
337341

338342
void Host::SystemLog(Severity severity, llvm::StringRef message) {
339343
HANDLE h = event_log->GetHandle();
340-
if (!h) {
344+
if (!h)
341345
return;
342-
}
343346

344-
LPCWSTR wide_message = AnsiToUtf16(message.str());
345-
if (!wide_message) {
347+
std::wstring wide_message = AnsiToUtf16(message.str());
348+
if (wide_message.empty())
346349
return;
347-
}
350+
351+
LPCWSTR msg_ptr = wide_message.c_str();
348352

349353
WORD event_type;
350354
switch (severity) {
@@ -359,7 +363,5 @@ void Host::SystemLog(Severity severity, llvm::StringRef message) {
359363
event_type = EVENTLOG_INFORMATION_TYPE;
360364
}
361365

362-
ReportEventW(h, event_type, 0, 0, nullptr, 1, 0, &wide_message, nullptr);
363-
364-
delete[] wide_message;
365-
}
366+
ReportEventW(h, event_type, 0, 0, nullptr, 1, 0, &msg_ptr, nullptr);
367+
}

0 commit comments

Comments
 (0)