[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 6 15:14:28 PST 2024


================
@@ -1444,16 +1444,26 @@ 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
----------------
HazardyKnusperkeks wrote:

```suggestion
            Next && Next->isNot(tok::r_brace)) { // Dangling comma.
```

https://github.com/llvm/llvm-project/pull/77045


More information about the cfe-commits mailing list