mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-04 16:26:46 +00:00
[clang] fix undefined behaviour in RawComment::getFormattedText()
Summary: Calling `back()` and `pop_back()` on the empty string is undefined behavior [1,2]. The issue manifested itself as an uncaught `std::out_of_range` exception when running `clangd` compiled on RHEL7 using devtoolset-9. [1] https://en.cppreference.com/w/cpp/string/basic_string/back [2] https://en.cppreference.com/w/cpp/string/basic_string/pop_back Fixes: 1ff7c32fc91c607b690d4bb9cf42f406be8dde68 Reviewers: teemperor, ioeric, cfe-commits Reviewed By: teemperor Subscribers: ilya-biryukov, kadircet, usaxena95 Tags: #clang Differential Revision: https://reviews.llvm.org/D77468
This commit is contained in:
parent
3c2dc28d81
commit
ad7211df6f
@ -431,7 +431,7 @@ std::string RawComment::getFormattedText(const SourceManager &SourceMgr,
|
||||
};
|
||||
|
||||
auto DropTrailingNewLines = [](std::string &Str) {
|
||||
while (Str.back() == '\n')
|
||||
while (!Str.empty() && Str.back() == '\n')
|
||||
Str.pop_back();
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user