From a18f45f556c781d711f82043bf451fcce8324163 Mon Sep 17 00:00:00 2001 From: Shivam Gupta Date: Thu, 11 Jul 2024 12:57:50 +0530 Subject: [PATCH] [lldb] Fix string truncation method when substring is the prefix of string (NFC) (#94785) Correct the method used to truncate the source_file string when substring is a prefix. The previous method used substr, which was changed to resize for clarity and efficiency. Caught by cppcheck - lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp:290:19: performance: Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr] Source code - source_file = source_file.substr(0, pos); Fix #91211 --------- Co-authored-by: Shivam Gupta --- lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp index e177c134fea20e..50b6a5c29a6572 100644 --- a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp +++ b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp @@ -287,7 +287,7 @@ Status PlatformAndroid::DownloadModuleSlice(const FileSpec &src_file_spec, static constexpr llvm::StringLiteral k_zip_separator("!/"); size_t pos = source_file.find(k_zip_separator); if (pos != std::string::npos) - source_file = source_file.substr(0, pos); + source_file.resize(pos); Status error; AdbClientUP adb(GetAdbClient(error));