[PATCH] D119625: Fix integer underflow bug when aligning code in clang-format
sstwcw via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 12 04:00:56 PST 2022
sstwcw created this revision.
sstwcw added a reviewer: clang-format.
sstwcw added a project: clang-format.
sstwcw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D119625
Files:
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16847,9 +16847,11 @@
"double b();",
Alignment);
unsigned OldColumnLimit = Alignment.ColumnLimit;
- // We need to set ColumnLimit to zero, in order to stress nested alignments,
- // otherwise the function parameters will be re-flowed onto a single line.
- Alignment.ColumnLimit = 0;
+ // We need to set ColumnLimit to a small number, in order to stress
+ // nested alignments, otherwise the function parameters will be
+ // re-flowed onto a single line. It also needs to be wide enough so
+ // that things still get aligned.
+ Alignment.ColumnLimit = 20;
EXPECT_EQ("int a(int x,\n"
" float y);\n"
"double b(int x,\n"
Index: clang/lib/Format/WhitespaceManager.cpp
===================================================================
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -575,7 +575,7 @@
if (!Changes[j].IsInsideToken)
LineLengthAfter += Changes[j].TokenLength;
}
- unsigned ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter;
+ int ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter;
// If we are restricted by the maximum column width, end the sequence.
if (ChangeMinColumn > MaxColumn || ChangeMaxColumn < MinColumn ||
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119625.408170.patch
Type: text/x-patch
Size: 1504 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220212/29856404/attachment.bin>
More information about the cfe-commits
mailing list