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

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 9 19:41:06 PST 2024


owenca wrote:

Please add an assertion in `WhitespaceManager.h`:
```
--- a/clang/lib/Format/WhitespaceManager.h
+++ b/clang/lib/Format/WhitespaceManager.h
@@ -282,6 +282,7 @@ private:
     for (auto PrevIter = Start; PrevIter != End; ++PrevIter) {
       // If we broke the line the initial spaces are already
       // accounted for.
+      assert(PrevIter->Index) < Changes.size();
       if (Changes[PrevIter->Index].NewlinesBefore > 0)
         NetWidth = 0;
       NetWidth +=
```

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


More information about the cfe-commits mailing list