Skip to content

Commit b8ec7ee

Browse files
committed
Clear the output string passed to GetHostName()
LLVM's wchar to UTF8 conversion routine expects an empty string to store the output. GetHostName() on Windows is sometimes called with a non-empty string which triggers an assert. The simple fix is to clear the output string before the conversion. llvm-svn: 358550
1 parent 990514c commit b8ec7ee

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lldb/source/Host/windows/HostInfoWindows.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ bool HostInfoWindows::GetHostname(std::string &s) {
9595
if (!::GetComputerNameW(buffer, &dwSize))
9696
return false;
9797

98+
// The conversion requires an empty string.
99+
s.clear();
98100
return llvm::convertWideToUTF8(buffer, s);
99101
}
100102

lldb/unittests/Host/HostInfoTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@ TEST_F(HostInfoTest, GetAugmentedArchSpec) {
5050
EXPECT_EQ(HostInfo::GetAugmentedArchSpec(LLDB_ARCH_DEFAULT).GetTriple(),
5151
HostInfo::GetArchitecture(HostInfo::eArchKindDefault).GetTriple());
5252
}
53+
54+
TEST_F(HostInfoTest, GetHostname) {
55+
// Check non-empty string input works correctly.
56+
std::string s("abc");
57+
EXPECT_TRUE(HostInfo::GetHostname(s));
58+
}

0 commit comments

Comments
 (0)