Author: asmith Date: Tue Apr 16 20:13:06 2019 New Revision: 358550 URL: http://llvm.org/viewvc/llvm-project?rev=358550&view=rev Log: 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. Modified: lldb/trunk/source/Host/windows/HostInfoWindows.cpp lldb/trunk/unittests/Host/HostInfoTest.cpp Modified: lldb/trunk/source/Host/windows/HostInfoWindows.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/HostInfoWindows.cpp?rev=358550&r1=358549&r2=358550&view=diff ============================================================================== --- lldb/trunk/source/Host/windows/HostInfoWindows.cpp (original) +++ lldb/trunk/source/Host/windows/HostInfoWindows.cpp Tue Apr 16 20:13:06 2019 @@ -95,6 +95,8 @@ bool HostInfoWindows::GetHostname(std::s if (!::GetComputerNameW(buffer, &dwSize)) return false; + // The conversion requires an empty string. + s.clear(); return llvm::convertWideToUTF8(buffer, s); } Modified: lldb/trunk/unittests/Host/HostInfoTest.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Host/HostInfoTest.cpp?rev=358550&r1=358549&r2=358550&view=diff ============================================================================== --- lldb/trunk/unittests/Host/HostInfoTest.cpp (original) +++ lldb/trunk/unittests/Host/HostInfoTest.cpp Tue Apr 16 20:13:06 2019 @@ -50,3 +50,9 @@ TEST_F(HostInfoTest, GetAugmentedArchSpe 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)); +} _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits