Skip to content

Commit b14c37a

Browse files
committed
[lldb/Platform] Return a std::string from GetSDKPath
Nothing guarantees that the objects in the StringMap remains at the same address when the StringMap grows. Therefore we shouldn't return a reference into the StringMap but return a copy of the string instead.
1 parent 329ebb8 commit b14c37a

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

lldb/include/lldb/Target/Platform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ class Platform : public PluginInterface {
435435
return lldb_private::ConstString();
436436
}
437437

438-
virtual llvm::StringRef GetSDKPath(lldb_private::XcodeSDK sdk) {
438+
virtual std::string GetSDKPath(lldb_private::XcodeSDK sdk) {
439439
return {};
440440
}
441441

lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,11 +1761,11 @@ PlatformDarwin::FindXcodeContentsDirectoryInPath(llvm::StringRef path) {
17611761
return {};
17621762
}
17631763

1764-
llvm::StringRef PlatformDarwin::GetSDKPath(XcodeSDK sdk) {
1764+
std::string PlatformDarwin::GetSDKPath(XcodeSDK sdk) {
17651765
std::string &path = m_sdk_path[sdk.GetString()];
1766-
if (path.empty())
1767-
path = HostInfo::GetXcodeSDK(sdk);
1768-
return path;
1766+
if (!path.empty())
1767+
return path;
1768+
return HostInfo::GetXcodeSDK(sdk);
17691769
}
17701770

17711771
FileSpec PlatformDarwin::GetXcodeContentsDirectory() {

lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class PlatformDarwin : public PlatformPOSIX {
8989
llvm::Expected<lldb_private::StructuredData::DictionarySP>
9090
FetchExtendedCrashInformation(lldb_private::Process &process) override;
9191

92-
llvm::StringRef GetSDKPath(lldb_private::XcodeSDK sdk) override;
92+
std::string GetSDKPath(lldb_private::XcodeSDK sdk) override;
9393

9494
static lldb_private::FileSpec GetXcodeContentsDirectory();
9595
static lldb_private::FileSpec GetXcodeDeveloperDirectory();

0 commit comments

Comments
 (0)