aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format/WhitespaceManager.cpp
diff options
context:
space:
mode:
authorOwen Pan <owenpiano@gmail.com>2023-11-17 14:35:30 -0800
committerGitHub <noreply@github.com>2023-11-17 14:35:30 -0800
commit5679f5515b8ba83c804ad871452a95565af76e19 (patch)
tree1948ce5f847e6d9dd6510c432af3ca230380a7ad /clang/lib/Format/WhitespaceManager.cpp
parent4323da926f12672daec7f59384bd153a7cf28674 (diff)
downloadllvm-5679f5515b8ba83c804ad871452a95565af76e19.zip
llvm-5679f5515b8ba83c804ad871452a95565af76e19.tar.gz
llvm-5679f5515b8ba83c804ad871452a95565af76e19.tar.bz2
[clang-format] Fix crashes in AlignArrayOfStructures (#72520)
Fixed #54815. Fixed #55269. Fixed #55493. Fixed #68431.
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 32d8b97..3bc6915 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1316,6 +1316,8 @@ void WhitespaceManager::alignArrayInitializersRightJustified(
auto Offset = std::distance(Cells.begin(), CellIter);
for (const auto *Next = CellIter->NextColumnElement; Next;
Next = Next->NextColumnElement) {
+ if (RowCount >= CellDescs.CellCounts.size())
+ break;
auto *Start = (Cells.begin() + RowCount * CellDescs.CellCounts[0]);
auto *End = Start + Offset;
ThisNetWidth = getNetWidth(Start, End, CellDescs.InitialSpaces);
@@ -1379,7 +1381,7 @@ void WhitespaceManager::alignArrayInitializersLeftJustified(
auto Offset = std::distance(Cells.begin(), CellIter);
for (const auto *Next = CellIter->NextColumnElement; Next;
Next = Next->NextColumnElement) {
- if (RowCount > CellDescs.CellCounts.size())
+ if (RowCount >= CellDescs.CellCounts.size())
break;
auto *Start = (Cells.begin() + RowCount * CellDescs.CellCounts[0]);
auto *End = Start + Offset;