Skip to content

Commit

Permalink
[lldb] Fix string truncation method when substring is the prefix of s…
Browse files Browse the repository at this point in the history
…tring (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 <[email protected]>
  • Loading branch information
xgupta and Shivam Gupta authored Jul 11, 2024
1 parent 6a90769 commit a18f45f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit a18f45f

Please sign in to comment.