diff options
| -rw-r--r-- | lldb/source/Host/windows/HostInfoWindows.cpp | 2 | ||||
| -rw-r--r-- | lldb/unittests/Host/HostInfoTest.cpp | 6 |
2 files changed, 8 insertions, 0 deletions
diff --git a/lldb/source/Host/windows/HostInfoWindows.cpp b/lldb/source/Host/windows/HostInfoWindows.cpp index 8cd8f2d2fc5..459703ff0ed 100644 --- a/lldb/source/Host/windows/HostInfoWindows.cpp +++ b/lldb/source/Host/windows/HostInfoWindows.cpp @@ -95,6 +95,8 @@ bool HostInfoWindows::GetHostname(std::string &s) { if (!::GetComputerNameW(buffer, &dwSize)) return false; + // The conversion requires an empty string. + s.clear(); return llvm::convertWideToUTF8(buffer, s); } diff --git a/lldb/unittests/Host/HostInfoTest.cpp b/lldb/unittests/Host/HostInfoTest.cpp index b4ba3194180..fb50e29eae5 100644 --- a/lldb/unittests/Host/HostInfoTest.cpp +++ b/lldb/unittests/Host/HostInfoTest.cpp @@ -50,3 +50,9 @@ TEST_F(HostInfoTest, GetAugmentedArchSpec) { EXPECT_EQ(HostInfo::GetAugmentedArchSpec(LLDB_ARCH_DEFAULT).GetTriple(), HostInfo::GetArchitecture(HostInfo::eArchKindDefault).GetTriple()); } + +TEST_F(HostInfoTest, GetHostname) { + // Check non-empty string input works correctly. + std::string s("abc"); + EXPECT_TRUE(HostInfo::GetHostname(s)); +} |

