[clang] fix undefined behaviour in RawComment::getFormattedText()
authorOliver Bruns <obruns@gmail.com>
Mon, 6 Apr 2020 08:38:30 +0000 (10:38 +0200)
committerRaphael Isemann <teemperor@gmail.com>
Mon, 6 Apr 2020 08:48:25 +0000 (10:48 +0200)
commitad7211df6f257e39da2e5a11b2456b4488f32a1e
treef99e36928a0d1f1a2497c99010919e24f702047d
parent3c2dc28d812c917e01f46b3bcf5b5e0a2a803276
[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
clang/lib/AST/RawCommentList.cpp