aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format/WhitespaceManager.cpp
diff options
context:
space:
mode:
authorXDeme <66138117+XDeme@users.noreply.github.com>2024-01-12 15:20:44 -0300
committerGitHub <noreply@github.com>2024-01-12 10:20:44 -0800
commit97a9dbb64919fe71379cda5f043633cbeb6438e5 (patch)
tree2d66175ed5032187e80969822947df7b2572c8fe /clang/lib/Format/WhitespaceManager.cpp
parent3bbc912d37f03d9ad3be330b81d91c2eaf6c37f2 (diff)
downloadllvm-97a9dbb64919fe71379cda5f043633cbeb6438e5.zip
llvm-97a9dbb64919fe71379cda5f043633cbeb6438e5.tar.gz
llvm-97a9dbb64919fe71379cda5f043633cbeb6438e5.tar.bz2
[clang-format] Handle possible crash in `getCells` (#77723)
Done as requested in llvm/llvm-project#77045 I have changed the test a bit, because since the root problem was fixed, the original test would possibly never crash.
Diffstat (limited to 'clang/lib/Format/WhitespaceManager.cpp')
-rw-r--r--clang/lib/Format/WhitespaceManager.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index f1d176f..8415c8d 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1451,8 +1451,10 @@ WhitespaceManager::CellDescriptions WhitespaceManager::getCells(unsigned Start,
} else if (C.Tok->is(tok::comma)) {
if (!Cells.empty())
Cells.back().EndIndex = i;
- if (C.Tok->getNextNonComment()->isNot(tok::r_brace)) // dangling comma
+ if (const auto *Next = C.Tok->getNextNonComment();
+ Next && Next->isNot(tok::r_brace)) { // dangling comma
++Cell;
+ }
}
} else if (Depth == 1) {
if (C.Tok == MatchingParen) {