This is an archive of the discontinued LLVM Phabricator instance.

[clang] fix undefined behaviour in RawComment::getFormattedText()
ClosedPublic

Authored by obruns on Apr 4 2020, 10:45 AM.

Details

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

Diff Detail

Event Timeline

obruns created this revision.Apr 4 2020, 10:45 AM
teemperor accepted this revision.Apr 6 2020, 12:42 AM

We don't usually use alternative operator spelling in Clang, but otherwise this LGTM. I'll land this for you.

This revision is now accepted and ready to land.Apr 6 2020, 12:42 AM

Landed as ad7211df6f257e39da2e5a11b2456b4488f32a1e

Btw, usually patches also need a test (especially if they are less trivial than this one).

This revision was automatically updated to reflect the committed changes.