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
if (!::GetComputerNameW(buffer, &dwSize))
return false;
+ // The conversion requires an empty string.
+ s.clear();
return llvm::convertWideToUTF8(buffer, s);
}
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));
+}